473,778 Members | 7,807 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Please help me in inserting data through DataTable

7 New Member
Hi experts,

I have a form in which there are 4 textboxes and few command buttons like New, View, Save, Delete. I want to insert the values entered in textboxes are to be stored in an Oracle database table 'mst_users' when the Save button is clicked.

I have declared the below variables in the form declaration section.

Dim conn As New OleDb.OleDbConn ection()
Dim da As New OleDb.OleDbData Adapter()
Dim dc As New OleDb.OleDbComm and()
Dim ds As New DataSet()
Dim dt As New DataTable()
Dim dr As DataRow()

I have a procedure as connectToDataba se() as below

Private Sub connectToDataba se()
Try

conn.Connection String = "provider=msdao ra;user id=scott;passwo rd=tiger;data source=orcl"
dc.Connection = conn
dc.CommandText = "select * from mst_users"
dc.CommandType = CommandType.Tex t
da.SelectComman d = dc

da.Fill(ds, "mst_users" )
Catch excp As Exception
MsgBox(excp.ToS tring())
End Try

End Sub

Then I have called that connectToDataba se() in the load event of the form as below

Private Sub frmMstUsers_Loa d(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Load
connectToDataba se()
End Sub

Then here is my code of click event for Save button.

Private Sub Button4_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button4.Click
dt = ds.Tables("mst_ users")

dr = dt.NewRow()
dr(0) = TextBox1.Text
dr(1) = TextBox2.Text
dr(2) = TextBox3.Text
dr(3) = ComboBox1.Text


dt.Rows.Add(dr)
da.Update(ds, "mst_users" )
MsgBox("Data saved sucessfuly")
End Sub

But a blue error line comes under each line of code in bold...... as below

dr = dt.NewRow() 'Value of type 'System.Data.Da taRow' cannot be converted to '1-dimensional array of System.Data.Dat aRow'.

dr(0) = TextBox1.Text 'Value of type 'String' cannot be converted to 'System.Data.Da taRow'.
dr(1) = TextBox2.Text 'same error
dr(2) = TextBox3.Text 'same error
dr(3) = ComboBox1.Text 'same error

Please help as I am trying so many experiments but not getting any solution..
Thanks a lot in advance
Manoj
Sep 11 '07 #1
0 980

Sign in to post your reply or Sign up for a free account.

Similar topics

23
2239
by: Eva | last post by:
Hi i am trying to insert a new row into one of my datatabels that i have in my dataset when a button is clicked. here is my code Dim ClientInsRow As DataRow = dtClient.NewRo ClientInsRow("Surname") = txtSurname.Tex ClientInsRow("Forename") = txtForename.Tex ClientInsRow("OrgName") = txtOrganisation.Tex ClientInsRow("Address") = txtAddress.Tex
4
22421
by: Deepankar | last post by:
Hi, I was trying to change an example for SQL Server to work with Access db to insert image data. I have everything working except getting the OleDbParameter type for the image column. The table in access is : img ( id number , name Text, img number
4
1527
by: Stephen | last post by:
I am trying to add some code to below to include a datatable and fill the datatable. The reason for doing this is so as I can check to see whether there are any rows returned by the stored procedure. If there are no records returned then this would give me an indicator and I can re-direct the page somewhere more appropriate. Well this is the theory. I have never used datatables before and am not sure how to implemenet what I want so I was...
2
4025
by: a | last post by:
NEW Post Here's my best guess at how to insert this dataset.... the code runs, but no new records are added to the sql table. I've read and split a delimited text file into a dataset. It looks fine in a datagrid (5 columns and 5,000 rows), but I've been trying, without success, to then insert the resulting dataset called "result" into a single sql table that has an auto-increment and PK column called ID,
6
2057
by: Pushpendra Vats | last post by:
Hi , I am trying to insert records into database. I am trying to write the following code. On button1 click event i am inserting five records and after that i am calling the update method of dataadapter to update the records in database. Records are inserting but all the five records have the same value and that too of that last ones.. More over i tried to use the acceptchanges methods for datatable and dataset but of no use
1
1779
by: Cooper | last post by:
If I have this as my XML file <?xml version="1.0" standalone="yes" ?> - <opml> - <body> - <outline text="RssImporter OPML"> <outline title="CNN" htmlUrl="" xmlUrl="http://rss.cnn.com/rss/cnn_topstories.rss" /> </outline> </body>
3
4274
by: rcoco | last post by:
Hi, I want to share this problem. I have a datagrid that will help me Insert data into sql database. So I made a button On my form so that when I press the button a new row on datagrid should be created and I could be able to insert data. But with this code below I've failed could someone help me and tell me where I'm going wrong: private void Page_Load(object sender, System.EventArgs e) { if (! IsPostBack)
4
5594
by: Manikandan | last post by:
Hi, I'm inserting a datetime values into sql server 2000 from c# SQL server table details Table name:date_test columnname datatype No int date_t DateTime C# coding
3
17543
by: joel | last post by:
Hi guys, Im new to vb.net and i have this problem how do i insert another row into my datatable... (i guess it's like creating a for loop or something i really have no idea)... in this code i can only insert a single row. help pls...
0
9629
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10296
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10127
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
10068
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
8954
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 project—planning, coding, testing, and deployment—without 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...
0
6723
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
5370
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...
0
5497
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2863
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.