![](/img/trans.png)
[英]How to save and load user input on WPF textboxes, richtextboxes and checkboxes
[英]How to save a WPF User registration Input to my SQL Server table?
從幾個小時開始我就有問題。 我嘗試將 WPF 應用程序中的用戶注冊輸入保存到我的 SQL 服務器表中。 這樣用戶每次使用應用程序時都不需要注冊,所以他們只需要登錄。 如果我嘗試注冊並且數據在我的 SQL 服務器表上沒有受到保護,我的應用程序就會崩潰。 繼承人的代碼我希望你能幫助我:
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace Zaphkiel_reloaded
{
/// <summary>
/// Interaction logic for Zaphkiel_Reloaded_Register_SQL.xaml
/// </summary>
public partial class Zaphkiel_Reloaded_Register_SQL : Window
{
SqlConnection con = new SqlConnection(@"Data Source=JOSH-PC-LA\SQLEXPRESSSERVER; Initial Catalog=LoginDB; Integrated Security=True");
SqlDataAdapter ad = new SqlDataAdapter();
DataSet ds = new DataSet();
public Zaphkiel_Reloaded_Register_SQL()
{
InitializeComponent();
}
private void btnRegister_Click(object sender, RoutedEventArgs e)
{
ds = new DataSet();
ad = new SqlDataAdapter("insert into tblUser (Username, Password) VALUES "+"('" + txtUsername+"', '" + txtPassword+"')", con);
ad.Fill(ds, "tblUser");
txtUsername.Clear();
txtPassword.Clear();
MessageBox.Show("Your account was created successfully!", "Info", MessageBoxButton.OK, MessageBoxImage.Information);
this.Close();
Zaphkiel_Reloaded_Login_SQL zaphkiel_login_screen = new Zaphkiel_Reloaded_Login_SQL();
zaphkiel_login_screen.Show();
}
}
}
(對不起,沒有足夠的代表發表評論)
請將錯誤消息以及有關數據庫表的信息添加到您的帖子中。
另外,您為此使用數據集對象有什么特別的原因嗎? 您可以只使用一個簡單的 SQLCommand,這是您在大多數示例中都能找到的
編輯:此處的示例和更多信息: https : //docs.microsoft.com/en-us/dotnet/api/system.data.sqlclient.sqlcommand?view=dotnet-plat-ext-5.0
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.