当我尝试执行存储过程并获取空数据集时出现此错误。
private SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["learnaspConnectionString"].ConnectionString);
protected void btnregister_Click(object sender, EventArgs e)
{
try
{
con.Open();
SqlCommand cmd = new SqlCommand("dbo.RegisterInsert", con);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter p1 = new SqlParameter("@fname", txtfname.Text);
SqlParameter p2 = new SqlParameter("@lname", txtlname.Text);
SqlParameter p3 = new SqlParameter("@company", txtcompany.Text);
SqlParameter p4 = new SqlParameter("@phone", txtphone.Text);
SqlParameter p5 = new SqlParameter("@address", txtaddress.Text);
SqlParameter p6 = new SqlParameter("@email", txtemail.Text);
cmd.Parameters.Add(p1);
cmd.Parameters.Add(p2);
cmd.Parameters.Add(p3);
cmd.Parameters.Add(p4);
cmd.Parameters.Add(p5);
cmd.Parameters.Add(p6);
cmd.ExecuteNonQuery();
con.Close();
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable dt = ds.Tables[0];
ListViewDetails.DataSource = ds;
ListViewDetails.DataBind();
lblmessage.Visible = true;
lblmessage.Text = "Registration Completed Successfully!";
}
catch (SqlException ex)
{
}
}
我的存储过程是:
CREATE PROCEDURE [dbo].[RegisterInsert]
-- Add the parameters for the stored procedure here
@fname nvarchar(50),
@lname nvarchar(50),
@company nvarchar(50),
@phone nvarchar(50),
@address nvarchar(250),
@email nvarchar(250)
SET NOCOUNT ON;
insert into [dbo].[register]
([fname],
[lname],
[company],
[phone],
[address],
[email])
values
(@fname,
@lname,
@company,
@phone,
@address,
@email)
END
当我运行我的代码时,我无法在 Listview 控件中获取显示数据。按钮单击事件将值存储在数据库中两次并给出错误“找不到表 0”。
请帮助我让我知道我的代码哪里错了。
提前致谢。