473,511 Members | 14,951 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What's wrong with this code? pls help!

navanova
30 New Member
I'm tring to insert to SQL server 2000 a data from a VB.net form. when i tried to run it , it says "Invalid object name 'Branch'." The code is found below: Help me pls!

Thank you.

Private Sub btnConnect_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click

Dim fir As String
Dim sec As String
'Dim myCommand As SqlClient.SqlCommand = ""
'Dim ra As Integer

fir = TextBox1.Text
sec = TextBox2.Text
'Try
Dim strCNStr As String = "Data Source=ITSAD;User ID=sa;Password=;"

Dim cnDB As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection

Dim cmdDB As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand("Insert into Branch(Fname,Lname) VALUES ('& fir & ','& sec & ')", cnDB)
Dim rdAuther As System.Data.SqlClient.SqlDataReader

cnDB.ConnectionString = strCNStr
cnDB.Open()


'Catch ex As Exception
' MsgBox("Hi")

'End Try
rdAuther = cmdDB.ExecuteReader()

While rdAuther.Read()
Debug.WriteLine(rdAuther.GetString(1))
End While

rdAuther.Close()
cnDB.Close()
End Sub
Feb 20 '07 #1
4 1112
hariharanmca
1,977 Top Contributor
I'm tring to insert to SQL server 2000 a data from a VB.net form. when i tried to run it , it says "Invalid object name 'Branch'." The code is found below: Help me pls!

Thank you.

Private Sub btnConnect_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click

Dim fir As String
Dim sec As String
'Dim myCommand As SqlClient.SqlCommand = ""
'Dim ra As Integer

fir = TextBox1.Text
sec = TextBox2.Text
'Try
Dim strCNStr As String = "Data Source=ITSAD;User ID=sa;Password=;"

Dim cnDB As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection

Dim cmdDB As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand("Insert into Branch(Fname,Lname) VALUES ('& fir & ','& sec & ')", cnDB)
Dim rdAuther As System.Data.SqlClient.SqlDataReader

cnDB.ConnectionString = strCNStr
cnDB.Open()


'Catch ex As Exception
' MsgBox("Hi")

'End Try
rdAuther = cmdDB.ExecuteReader()

While rdAuther.Read()
Debug.WriteLine(rdAuther.GetString(1))
End While

rdAuther.Close()
cnDB.Close()
End Sub

i thing Branch table or column is not found
Feb 20 '07 #2
Maira
7 New Member
I'm tring to insert to SQL server 2000 a data from a VB.net form. when i tried to run it , it says "Invalid object name 'Branch'." The code is found below: Help me pls!

Thank you.

Private Sub btnConnect_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click

Dim fir As String
Dim sec As String
'Dim myCommand As SqlClient.SqlCommand = ""
'Dim ra As Integer

fir = TextBox1.Text
sec = TextBox2.Text
'Try
Dim strCNStr As String = "Data Source=ITSAD;User ID=sa;Password=;"

Dim cnDB As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection

Dim cmdDB As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand("Insert into Branch(Fname,Lname) VALUES ('& fir & ','& sec & ')", cnDB)
Dim rdAuther As System.Data.SqlClient.SqlDataReader

cnDB.ConnectionString = strCNStr
cnDB.Open()


'Catch ex As Exception
' MsgBox("Hi")

'End Try
rdAuther = cmdDB.ExecuteReader()

While rdAuther.Read()
Debug.WriteLine(rdAuther.GetString(1))
End While

rdAuther.Close()
cnDB.Close()
End Sub
hi,
First your connection string is wrong. you omitted the Database Name.so it would be:
Dim strCNStr As String = "Data Source=ITSAD;Initial Catalog=myDatabaseName;User ID=sa;Password=;"

Second you must be sure to create the table Branch in your database. and you must modify your query to (put " instead of ' for strings) so it would be
Dim strcmd As String = "Insert into Branch(Fname,Lname) VALUES ('" & fir & "','" & sec & "')"
Feb 20 '07 #3
navanova
30 New Member
It Works! Thank you very much!
Feb 20 '07 #4
enreil
86 New Member
If I were you I'd look at using SQL parameters if this application is going to be deployed. This means your insert string looks like:

Dim strcmd As String = "Insert into Branch(Fname,Lname) VALUES (@pfir, @psec)"
strcmd.Parameters.Add("@pfir", fir)
strcmd.Parameters.Add("@psec", sec)

hi,
First your connection string is wrong. you omitted the Database Name.so it would be:
Dim strCNStr As String = "Data Source=ITSAD;Initial Catalog=myDatabaseName;User ID=sa;Password=;"

Second you must be sure to create the table Branch in your database. and you must modify your query to (put " instead of ' for strings) so it would be
Dim strcmd As String = "Insert into Branch(Fname,Lname) VALUES ('" & fir & "','" & sec & "')"
Feb 20 '07 #5

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

Similar topics

220
18806
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
125
14543
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
2
4352
by: Moon | last post by:
Seems I still haven't got the hang of all those window generating code in Javascript. I've got a page with about 15 photo thumbnails. When you click on a thumbnail a new window pops up which shows...
35
3294
by: GTO | last post by:
I do not believe that C# is the future of C++. I also do not believe that adding two thousand new library functions to the standard library is the future of C++. But what is the future of C++? Is...
121
9908
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
3
1557
by: Kate Luu | last post by:
I have down load some source codes from the internet and it wasn't worked right, but I'm really know what's wrong about it. May some expert help me please...I'm deeply appreciated for your help....
51
13297
by: WindAndWaves | last post by:
Can anyone tell me what is wrong with the goto command. I noticed it is one of those NEVER USE. I can understand that it may lead to confusing code, but I often use it like this: is this...
6
2632
by: Niklaus | last post by:
Hi, Can someone point out what is wrong with this code ? How can i make it better optimize it. When run it gives me seg fault in linux. But windows it works fine(runs for a long time). Do we...
98
4490
by: tjb | last post by:
I often see code like this: /// <summary> /// Removes a node. /// </summary> /// <param name="node">The node to remove.</param> public void RemoveNode(Node node) { <...> }
11
2049
by: frankie_85 | last post by:
Hi everyone, I just made a simple code which is part of my assignment but I can't figure it out what's wrong with it. (always give me error messages) What the code basically does is: a...
0
7237
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,...
0
7349
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,...
1
7074
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...
0
5659
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,...
1
5063
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...
0
4734
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...
0
1572
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
445
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...

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.