Last post Jul 30, 2009 01:27 AM by veenag81
Jul 07, 2009 06:54 PM|jcook331|LINK
I'm inserting a new record into a table by using a button that call a stored procedure. When the page refreshes I need the gridview to go into the update mode after the insert. Is this possible and would I do this in the VB code or in ASP?
Partial Class _Default
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim conn As SqlConnection = New SqlConnection()
Dim cmd As SqlCommand = New SqlCommand()
conn.ConnectionString = ConfigurationManager.ConnectionStrings("DatabaseConnectionString1").ConnectionString
cmd.Connection = conn
cmd.CommandText = "insert_goal"
cmd.CommandType = Data.CommandType.StoredProcedure
'Pass parameters required by the stored procedure
.Parameters.Add(New SqlParameter("@year", Data.SqlDbType.NChar, 10))
'.Parameters("@year").Value = "2009-2010"
.Parameters.Add(New SqlParameter("@unit", Data.SqlDbType.VarChar, 50))
'.Parameters("@unit").Value = "welding"
.Parameters.Add(New SqlParameter("@ignum", Data.SqlDbType.TinyInt, 2))
'.Parameters("@ignum").Value = 1
Catch ex As Exception
Jul 08, 2009 01:25 AM|veenag81|LINK
Hello, After cmd.ExecuteQuery() write the code for binding your gridview as below ---->
gridviewName.Datasource = dtYourDatasetName;
So u get the data which u inserted in GridView Also.
Jul 08, 2009 01:26 AM|veenag81|LINK
Jul 08, 2009 11:19 AM|jcook331|LINK
I tried your suggestion, but I had problems with it. If I put the dt in from of the datasetname then I got an error. If I left the dt off then the page came up and the insert button worked correctly, but it did not put that record into edit mode. Below
is the code I added. Thanks.
'GridView1.DataSource = dtSqlDataSource1
GridView1.DataSource = SqlDataSource1
Jul 09, 2009 12:06 AM|veenag81|LINK
Hello, Try for following Code ---->
cmd.CommandText = qry
adp.SelectCommand = cmd;
ds = new DataSet();
GridView1.DataSource = ds
Jul 13, 2009 03:14 PM|jcook331|LINK
This isn't working either. It will not accept anything with adp in front of it. Is this C# code? I'm using VB. I'm new to this so I'm not sure. Thanks.
Jul 15, 2009 04:22 AM|veenag81|LINK
Hello, yes my code is in C#. Now try for this. Below code is VB.Net ---->
Jul 15, 2009 09:35 AM|jcook331|LINK
It still will not accept the lines with adp. Is there an include that I need to use this? Also, I'm not sure what to put in place of qry.
Jul 28, 2009 05:55 PM|jcook331|LINK
I've tried the code you gave me, but I keep getting the error
"Name adp is not declared".
Is there something I'm missing. This is the code I'm using. Thanks.
Partial Class IG_Maintain
conn.ConnectionString = ConfigurationManager.ConnectionStrings("DatabaseConnectionString2").ConnectionString
.Parameters.Add(New SqlParameter("@yeardd", Data.SqlDbType.NChar, 10))
.Parameters.Add(New SqlParameter("@unitdd", Data.SqlDbType.VarChar, 50))
.Parameters.Add(New SqlParameter("@ignumdd", Data.SqlDbType.TinyInt, 2))
cmd.CommandText = "update goals where year = @yeardd and unit = @unitdd and ignum = ignumdd"
adp.selectcommand = cmd
'ds = New dataset()
GridView1.DataSource = SqlDataSource3
Jul 30, 2009 01:27 AM|veenag81|LINK
Hello, this is sample which u can apply in your code