473,938 Members | 27,770 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Insert a new row using asp.net datagrid

I am having problems with the following code. I am trying to update my db table Categories in Northwind. I have borrowed this code from www.dotnetjohn.com/articles/articleid27.aspx Although it works on dotnetjohn website, I cannot replicate the code successfully. I have a datagrid filled with data and two textboxes with an “Insert” button. When the button is pressed, the text entered into the two textboxes is to be added to the table Categories in Northwind db. I cannot get the click event to update the database and add a new record entry. The page_load fills the datagrid with data from a SELECT statement. The Insert_Click should take the entries from two textboxes and insert them into the Northwinds database Categories table. I have enclosed the basic components of my .aspx.vb page for the Page_Load, Insert_Click, and FilltheGrid() method. I am confused as to my problem. Please help. Thank you. If you need more data just ask me to provide it

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Loa

If Not Page.IsPostBack The
Dim dsCategories As DataSe
Dim temp As Object = Session("Catego ries"
If temp Is Nothing The
dsCategories = New DataSe
Dim sqlConn As String = "server=BP-ADOVE;database= northwind;uid=s a;pwd=
Dim selectText As Strin
selectText = "SELECT categoryName, Description FROM Categories WHERE (CategoryID = 1 or CategoryID=2 or CategoryID=3 or CategoryID=9)
Dim cmdCategories As SqlDataAdapter = New SqlDataAdapter( selectText, sqlConn
cmdCategories.F ill(dsCategorie s, "Categories "
Session("Catego ries") = dsCategorie

Els
dsCategories = CType(temp, DataSet
End I
dgAction.DataSo urce = dsCategories.Ta bles("Categorie s"
dgAction.DataBi nd(
End I
End Su

Sub btnInsert_Click (ByVal Sender As Object, ByVal e As EventArgs) Handles btnInsertAction .Clic
If Page.IsValid The
Dim strDate As Strin
Dim strDesc As Strin

objConn = New SqlConnection(C onfigurationSet tings.AppSettin gs("connectionS tring")
objConn.Open(
strDate = txtActionDate.T ext.Trim(
strDesc = txtDescription. Text.Trim(
strSql = "INSERT INTO Employees (LastName, FirstName) "
& "VALUES ('" & strDate & "', '" & strDesc & "')
objCmd = New SqlCommand(strS ql, objConn
objCmd.ExecuteN onQuery(

'Dim cmdCategories As SqlDataAdapter = New SqlDataAdapter( strSql, objConn
'cmdCategories. Fill(dsCategori es, "Categories "
'dgAction.DataS ource = dsCategories.Ta bles(0).Default Vie
'dgAction.DataB ind(

objCmd.ExecuteN onQuery(
objConn.Close(
FillTheGrid(

End I
End Su

Sub FillTheGrid(
'Dim adoComponent As ADOCOM.DataClas s = New ADOCOM.DataClas
'Dim adoRS As ADODB._Recordse t = adoComponent.Ge tData(

Dim myDA As SqlDataAdapter = New SqlDataAdapte
Dim ds As DataSet = New DataSe
myDA.InsertComm and = objCm

Dim dt As DataTable = ds.Tables("Empl oyees"
myDA.TableMappi ngs.Add("Employ ees", "Employees"

myDA.Update(ds, "Employees"

'dataAdapter.Fi ll(ds
dgAction.DataSo urce = ds.Tables("Empl oyees") '.DefaultVie
dgAction.DataBi nd(

End Sub
Nov 22 '05 #1
0 2198

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2213
by: Christopher | last post by:
I AM GETTING A SYSTEM.DATA.SQLCLIENT.SQLEXCEPTION ERROR WHEN ATTEMPTING TO INSERT DATA INTO A SINGLE TABLE THROUGH A GRID //If this is due to a spelling error, i will //inflict a ritual beating upon myself !!!!!!!!!!!! TABLE SCRIPT
5
7053
by: SSP | last post by:
Dear ASP.NETers, How would I insert multiple rows of data from a web form? Are there any tute's and stuff around. Couldn't find any myself. Thanks in advance. SSP
1
1692
by: tshad | last post by:
I can't seem to get insert into a DataGrid to work. I am using an example from the net and made changes to work on my computer. The grid comes up fine. The edit boxes in the footer are there. But when I press the "insert" link, it never seems to go to the DataGrid1_ItemCommand routine. ************************************************************************************** <%@ Page Language="vb" trace="true" debug="true" %> <%@ Import...
2
1708
by: Stuart | last post by:
Hi there I am using the following to take an account number from a datagrid in to another page and use it to load specific details according to the account number: Public Sub CustomerSearchGrid_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles CustomerSearchGrid.ItemCommand If e.Item.ItemIndex >= 0 Then
0
1531
by: Eustice Scrubb | last post by:
In line coding problem. Here's my code: <script language="VB" runat="server"> Dim myConnection As SqlConnection Sub Page_Load(Src As Object, e As EventArgs) ' Create a connection to the SQL Server myConnection = New SqlConnection("Data Source=SERVER;" _ & "Initial Catalog=database;User Id=user;Password=password;")
1
1340
by: schapopa | last post by:
Hi Everybody, I have a datagrid and I am using sqlcommandbuilder for update and insert of the data. I have two questions related to insert new row in datagrid. When I get to the new row how can I make first column(which is my primary kay) filled with some value?? Second, how can I add new row to the datagrid by using the button on the bottom. What is the even for the datagrid.
3
2022
by: pjcraig | last post by:
This is driving me crazy! I have a form that a user will access from another form by selecting the item that they wish to view. When they open the new form, I pass through the id of the item they selected so that only the details for the given item are displayed. In order for this to work, I using the following code.... This is working no problems at all: SqlSelectCommand1.Parameters("@blast_no").Value = blastNo So this displays the...
1
3095
by: glenn | last post by:
Hi folks, I am using an Access database, VB.NET and ADO.NET working with a DataGrid control. MY datagrid table has both a date_sent and a date_ans field. When I Insert a record in my SQL statement, I insert a date_sent but I need to insert a blank date_ans field. date_sent is the date when a question was sent to a group from a web form and date_ans is the date when a question was answered.
0
2211
by: danishce | last post by:
Hello, I want to insert data directly into my windows form data grid and load a combobox(userid) in the 1st column of data grid,a textbox(password) in 2nd column of datagrid. The code for insert data is: dim cmd as new oledbcommand("insert into table(userid,password) values('" & cmbcol1.text & "','" & txtcol2.text & "')",connection) dim da as new oledbdataadapter dim ds as new dataset da.selectcommand=cmd da.fill(ds) messagebox.show...
5
5488
by: Me LK | last post by:
I need to add a line to choose a size into a dropdown . Since I have the dropdown nested inside a datagrid this is not working.When a page displays there are several rows of dropdowns but only the top dropdown has the option added. The others do not. I am using the following code Dim ddlPsize As DropDownList ddlPsize = (itemInfo.Items(0).FindControl("ddlsizes")) ddlPsize.Items.Insert(0, "Choose a Size")
0
9963
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11098
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11281
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10649
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9853
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8207
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7377
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6072
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4441
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.