插入到sql的数据在数据网格显示中不断变化。但它并没有完全显现出来。例如,我在这张表中有四列。在第一次运行时显示4列数据。但是当我将数据插入表格时,只有两个列数据才会出现。
单击按钮时,Column1,第4列未出现在datagridview中。 请注意。第1列(ID)自动增量和列(时间)是自动时间戳。 我的sql代码是
USE [d]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[data](
[ID] [int] IDENTITY(1,1) NOT NULL,
[no] [nvarchar](255) NULL,
[name] [nvarchar](255) NULL,
[time] [datetime] NULL,
PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
我的vb代码是
protected void button1_Click_1(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection();
con.ConnectionString = ("Data Source=PC;Initial Catalog=d;Integrated Security=True");
con.Open();
String st = "INSERT INTO data(no,name,time)values (@no, @name, GETDATE())";
SqlCommand cmd = new SqlCommand(st, con);
cmd.Parameters.AddWithValue("@no", textBox5.Text);
cmd.Parameters.AddWithValue("@name", textBox6.Text);
cmd.ExecuteNonQuery();
MessageBox.Show("Saved");
con.Close();
textBox5.Text = "";
textBox6.Text = "";
dataBindingSource5.DataSource = dataTableAdapter.GetData();
dataBindingSource5.ResetBindings(false);
//// dataGridView2.Refresh();
}
答案 0 :(得分:0)
问题解决了。将适配器详细信息更改为dataBindingSource5.DataSource = dataTableAdapter4.GetData();.
...谢谢