MSDN连接帮助:
WINFROM
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/vbcon/html/vbwlkwalkthroughdisplayingdatafromsingletableinwindowsform.htm
WEBFROM
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/vsintro7/html/vcwlkWalkthroughWebForms.htm
WINFROM
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/vbcon/html/vbwlkwalkthroughdisplayingdatafromsingletableinwindowsform.htm
WEBFROM
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/vsintro7/html/vcwlkWalkthroughWebForms.htm
try
{
sqlConnection1.Open();
DataRow drAdd;
drAdd = dataSet11.Tables["表1"].NewRow();
drAdd[0] = textBox1.Text;
drAdd[1] = textBox2.text;
dataSet11.Tables["表1"].Rows.Add(drAdd);
sqlDataAdapter1.Update(dataSet11,"表1");
sqlConnection1.Close();
MessageBox.Show("记录成功!");
}
catch(SqlException sqle)
{
sqlConnection1.Close();
MessageBox.Show(sqle.Message);
}
catch(Exception e1)
{
sqlConnection1.Close();
MessageBox.Show(e1.Message);
}//删除
if(MessageBox.Show("删除后数据将无法恢复\n确定删除?","删除确认",MessageBoxButtons.YesNo) == DialogResult.Yes)
{
try
{
sqlConnection1.Open();
string deleteCommand1 = "DELETE from 表1 where num = 111";
sqlCommand1 = new SqlCommand(deleteCommand1,sqlConnection1);
sqlCommand1.ExecuteNonQuery();
sqlDataAdapter1.Update(DataSet11,"表1");
MessageBox.Show("资料已删除!");
sqlConnection1.Close();
}
catch(SqlException sqle)
{
MessageBox.Show(sqle.Message);
sqlConnection1.Close();
}
catch(Exception e1)
{
MessageBox.Show(e1.Message);
sqlConnection1.Close();
}//更新try
{
sqlConnection1.Open();
string upDateCommand1 = "UPDATE 表1 SET 姓名='"+textBox1.Text+"',学号='"+ textBox2.Text +"' where 学号='"+ textBox3.Text +"'";
sqlCommand3 = new SqlCommand(upDateCommand1,sqlConnection1);
sqlCommand3.ExecuteNonQuery();
sqlDataAdapter1.Update(DataSet11,"表1");
MessageBox.Show("修改成功!");
}
catch(SqlException sqle)
{
MessageBox.Show(sqle.Message);
sqlConnection1.Close();
}
catch(Exception e1)
{
MessageBox.Show(e1.Message);
sqlConnection1.Close();
}
// 查询
sqlConnection1.Open();
string sql;
if(comboBox2.Text!= "")
{
sql="select * from 表1 where 学号='"+ comboBox2.Text +"'";
SqlCommand myCommand = new SqlCommand(sql,sqlConnection1);
SqlDataReader myReader = myCommand.ExecuteReader();
try
{
if (myReader.Read())
{
textBox1.Text = myReader.GetSqlString(0).ToString();myReader.Close();
sqlConnection1.Close();
textBox10.Text = comboBox2.Text;
textBox58.Text = textBox10.Text;
textBox49.Text = textBox10.Text;
}
else
{
MessageBox.Show("没有<"+comboBox2.Text+">的相关信息!");
}
} finally
{
myReader.Close();
sqlConnection1.Close();
}
}
else
{
MessageBox.Show("请输入查询条件!");
sqlConnection1.Close();
}
这是最好入门教程
上面有好多的“示例和演习”
买一套vs.net盘,6张的也可以,7张的也可以