Click here to Skip to main content
15,889,865 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
a insert in to sql is keep changing in datagrid display. But its not appearing fully. example i have got four column in this table. While run first time its displaying 4 columns data. But while i inserting the data in to table then two column data only its coming.

Column1,Column 4 is not appearing in datagridview while button click . please note that. Column 1(ID) auto-increment and Column(time) is autotimestamp. my sql code is


What I have tried:

SQL
SE [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 CODE
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();
            
        }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900