它在SQL数据库中显示System.Data.DataRowView [英] It's showing System.Data.DataRowView in SQL database
本文介绍了它在SQL数据库中显示System.Data.DataRowView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
private void button_Pass_Click(object sender,EventArgs e)
{
SqlConnection con1 = new SqlConnection(Data Source = .\\SQLEXPRESS; Initial Catalog = db-ub; Integrated Security = True);
SqlCommand cmd1 =新的SqlCommand(插入访问者(To_Whom)值(@whom),con1);
con1.Open();
int o = cmd1.ExecuteNonQuery();
MessageBox.Show(o +:已插入记录);
}
private void Form3_Load(object sender,EventArgs e)
{
SqlConnection con = new SqlConnection(Data Source = .\\SQLEXPRESS; Initial Catalog = db-ub; Integrated Security = True);
con.Open();
SqlCommand sc = new SqlCommand(从Employees中选择Employee_Name,con);
SqlDataReader阅读器;
reader = sc.ExecuteReader();
DataTable dt = new DataTable();
dt.Columns.Add(Employee_Name,typeof(string));
dt.Load(读者);
comboBox_TOWHOM.DataSource = dt;
comboBox_TOWHOM.DisplayMember =Employee_Name;
con.Close();
}
(/ *我有两个表访客和员工,我有Employee_Name。在我的form3中有一个组合框,它从员工将表存储到访客表中。一切都很好,但在访客表中,它显示To_Whom列下的System.Data.DataRowView。请帮助。* /)
解决方案
你有这个:
SqlConnection con1 = new SqlConnection( 数据源=。\\SQLEXPRESS;初始目录= db-ub;集成安全性=真);
SqlCommand cmd1 =新的SqlCommand( 插入访问者(To_Whom)值(@whom) ,con1);
con1。打开();
int o = cmd1.ExecuteNonQuery();
你告诉sql期望一个参数但从未提供参数的地方。
您需要添加
cmd1.Parameters.AddWithValue( @ which,someValue);
。
private void button_Pass_Click(object sender, EventArgs e) { SqlConnection con1 = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=db-ub;Integrated Security=True"); SqlCommand cmd1 = new SqlCommand("Insert into Visitors(To_Whom) values (@whom)", con1); con1.Open(); int o = cmd1.ExecuteNonQuery(); MessageBox.Show(o + " :Record has been inserted"); } private void Form3_Load(object sender, EventArgs e) { SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=db-ub;Integrated Security=True"); con.Open(); SqlCommand sc = new SqlCommand("select Employee_Name from Employees",con); SqlDataReader reader; reader = sc.ExecuteReader(); DataTable dt = new DataTable(); dt.Columns.Add("Employee_Name", typeof(string)); dt.Load(reader); comboBox_TOWHOM.DataSource = dt; comboBox_TOWHOM.DisplayMember = "Employee_Name"; con.Close(); } (/*I have two tables "Visitors" and "Employees", I have Employee_Name. In my form3 there is a combobox which is fetching data from the "Employees" table and storing it to the "Visitors" table. Everything is fine but in the "Visitors" table it’s showing "System.Data.DataRowView" under To_Whom column. Please help. */)
解决方案
You have this:
SqlConnection con1 = new SqlConnection("Data Source=.\\SQLEXPRESS;Initial Catalog=db-ub;Integrated Security=True"); SqlCommand cmd1 = new SqlCommand("Insert into Visitors(To_Whom) values (@whom)", con1); con1.Open(); int o = cmd1.ExecuteNonQuery();
where you told the sql to expect a parameter but then never supplied the parameter.
You need to add
cmd1.Parameters.AddWithValue("@whom", someValue);
before you call ExecuteNonQuery.
这篇关于它在SQL数据库中显示System.Data.DataRowView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文