我想通过调用存储过程进行数据插入,程序如下
但是问题在于,运行点击按钮后,数据库实际数据并没有增加,请问下问题是出在哪?
谢谢了.
存储过程为:create procedure addstudent
(@stu_lname char(20),@stu_fname char(20),@id int)
as
insert students
(stu_lname,stu_fname,id)
values
(@stu_lname,@stu_fname,@id)
go
下面是主程序:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace WindowsApplication21
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void buttonok_Click(object sender, EventArgs e)
{ //数据库连接
string afile = " server=127.0.0.1; uid=joerson;pwd=123; database=mysql";
SqlConnection connet = new SqlConnection (afile);
connet.Open();
//数据库操作
SqlCommand acmd = new SqlCommand("addstudent",connet);
acmd.CommandType = CommandType.StoredProcedure;
//赋值
acmd.Parameters.Add(new SqlParameter ("@stu_lname",SqlDbType.Char,20));
acmd.Parameters["@stu_lname"].Value = textBox1.Text;
acmd.Parameters.Add(new SqlParameter ("@stu_fname",SqlDbType.Char,20));
acmd.Parameters["@stu_fname"].Value=textBox2.Text;
acmd.Parameters.Add(new SqlParameter("@id",SqlDbType.Int));
acmd.Parameters["@id"].Value=textBox3.Text;
acmd.ExecuteNonQuery();
connet.Close();
}
[此贴子已经被作者于2006-12-1 12:57:24编辑过]