一:数据库连接代码:
SqlConnection objSqlConnection = new SqlConnection ("server = 127.0.0.1;uid = sa; pwd =;database =test");
objSqlConnection.Open();
二:数据库的添加记录代码:
int i = 0;
string s1 = "", s2 = "";
i = Convert.ToInt16(textBox1.Text);
s1 = textBox2.Text;
s2 = textBox3.Text;
SqlConnection objSqlConnection = new SqlConnection("server = 127.0.0.1;uid = sa; pwd =;database =test");
objSqlConnection.Open();
MessageBox.Show("数据库连接成功", "好");
try
{
SqlCommand sqlcom = new SqlCommand("insert into info(id,name,sex) values( " + i + ",'" + s1 + "','" + s2 + "')", objSqlConnection);
sqlcom.ExecuteNonQuery();
MessageBox.Show("添加成功!", "啊");
}
catch (Exception a)
{
MessageBox.Show(a.ToString());
}
MessageBox.Show("添加成功!", "啊");
}
三:数据库的修改代码:
int i = 0;
string s1 = "", s2 = "";
s1 = textBox2.Text;
s2 = textBox3.Text;
if (textBox1.Text.Length == 0)
i = 0;