'Saving data into database table
I have this code that takes two information from user ( username , password )
How can I save these information into database table .
Note: I have already made database table in SQL server .
I get this error when I run the form :
System.Data.SqlClient.SqlException: 'A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)'
string sql = @"Data Source=(local)\(servername);Initial Catalog=(TestDB);Integrated Security=True;";
public Form1()
{
InitializeComponent();
}
private void Login_button_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(sql);
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "LoginTable";
cmd.Parameters.AddWithValue("@Username", username_textBox);
cmd.Parameters.AddWithValue("@Password", pass_textBox);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Register succesful");
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
