473,668 Members | 2,383 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_Clic k_1(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles btnConnect.Clic k

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

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

Dim cnDB As System.Data.Sql Client.SqlConne ction = New System.Data.Sql Client.SqlConne ction

Dim cmdDB As System.Data.Sql Client.SqlComma nd = New System.Data.Sql Client.SqlComma nd("Insert into Branch(Fname,Ln ame) VALUES ('& fir & ','& sec & ')", cnDB)
Dim rdAuther As System.Data.Sql Client.SqlDataR eader

cnDB.Connection String = strCNStr
cnDB.Open()


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

'End Try
rdAuther = cmdDB.ExecuteRe ader()

While rdAuther.Read()
Debug.WriteLine (rdAuther.GetSt ring(1))
End While

rdAuther.Close( )
cnDB.Close()
End Sub
Feb 20 '07 #1
4 1119
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_Clic k_1(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles btnConnect.Clic k

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

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

Dim cnDB As System.Data.Sql Client.SqlConne ction = New System.Data.Sql Client.SqlConne ction

Dim cmdDB As System.Data.Sql Client.SqlComma nd = New System.Data.Sql Client.SqlComma nd("Insert into Branch(Fname,Ln ame) VALUES ('& fir & ','& sec & ')", cnDB)
Dim rdAuther As System.Data.Sql Client.SqlDataR eader

cnDB.Connection String = strCNStr
cnDB.Open()


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

'End Try
rdAuther = cmdDB.ExecuteRe ader()

While rdAuther.Read()
Debug.WriteLine (rdAuther.GetSt ring(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_Clic k_1(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles btnConnect.Clic k

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

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

Dim cnDB As System.Data.Sql Client.SqlConne ction = New System.Data.Sql Client.SqlConne ction

Dim cmdDB As System.Data.Sql Client.SqlComma nd = New System.Data.Sql Client.SqlComma nd("Insert into Branch(Fname,Ln ame) VALUES ('& fir & ','& sec & ')", cnDB)
Dim rdAuther As System.Data.Sql Client.SqlDataR eader

cnDB.Connection String = strCNStr
cnDB.Open()


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

'End Try
rdAuther = cmdDB.ExecuteRe ader()

While rdAuther.Read()
Debug.WriteLine (rdAuther.GetSt ring(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;In itial Catalog=myDatab aseName;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,Ln ame) 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,Ln ame) VALUES (@pfir, @psec)"
strcmd.Paramete rs.Add("@pfir", fir)
strcmd.Paramete rs.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;In itial Catalog=myDatab aseName;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,Ln ame) VALUES ('" & fir & "','" & sec & "')"
Feb 20 '07 #5

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

Similar topics

220
19001
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 any preconceived ideas about it. I have noticed, however, that every programmer I talk to who's aware of Python is also talking about Ruby. So it seems that Ruby has the potential to compete with and displace Python. I'm curious on what basis it...
125
14708
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 software giant such as Microsoft SQL Server, Oracle, and Sybase? Is PostgreSQL reliable enough to be used for high-end commercial application? Thanks
2
4365
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 the enlarged version of said thumbnail. This works fine on all current browsers I've tested. However, in case I do not close the popup but click on another thumbnail instead, only IE replaces the enlarged pic by the new one, Firebird and Opera...
35
3326
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 it as good as a programming language can get? Like so many of you, I programmed speech recognizers, image recognition systems, a portion of a chess program, lots of numeric code using STL, and tons of other applications in C++, (even firmware...
121
10029
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 support IDEs are DreamWeaver 8 and Zend PHP Studio. DreamWeaver provides full support for Unicode. However, DreamWeaver is a web editor rather than a PHP IDE. It only supports basic IntelliSense (or code completion) and doesn't have anything...
3
1565
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. Have a nice day... Kate the code look like this:
51
13349
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 wrong????? Function x select case z
6
2646
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 have something like stack size growing enormously and then saying you can't access ,so a segfault ? It would be helpful if someone can run the code and give me the output. It takes a long time on my PC.
98
4570
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
2065
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 function that takes one floating point number x as its argument and returns (the square root of the absolute value of x) plus (5 times x cubed).
0
8459
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
8890
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
8791
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
8577
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,...
1
6206
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
5677
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
4202
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
2018
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1783
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.