473,386 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

i am new to programing help me out

I want to insert values from vb textbox in sql table named [home] and my code is


Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim result As Integer
Dim conn As New OleDb.OleDbConnection("provider=SQLOLEDB;User ID=sa;password=xxxxxx;Initial Catalog=first;data source=NAVEEN;")
conn.Open()
Dim insert1 As New OleDb.OleDbCommand
insert1 = New OleDb.OleDbCommand("insert into home values('" + TextBox1.Text + "','" + TextBox2.Text + "'),conn")
insert1.CommandType = CommandType.Text
result = insert1.ExecuteNonQuery()
conn.Close()

error message that i get is

ExecuteNonQuery: Connection property has not been initialized.


please help out

thanks
Jun 9 '08 #1
2 808
jamesd0142
469 256MB
Imports System.Data.OleDb

Expand|Select|Wrap|Line Numbers
  1. Try
  2.             Dim StrConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\Users\Users.mdb"
  3.             Dim oConn As New System.Data.OleDb.OleDbConnection(StrConn)
  4.             Dim con As New System.Data.OleDb.OleDbCommand
  5.             con.Connection = oConn
  6.             con.CommandType = CommandType.Text
  7.             con.CommandText = ""            
  8.             oConn.Open()
  9.             con.ExecuteNonQuery()
  10.             oConn.Close()
  11.         Catch
  12.         End Try
  13.  
Jun 9 '08 #2
Curtis Rutland
3,256 Expert 2GB
Part of your problem seems to be that you have a quote after conn. But let me show you an easier way to build your command string:
Expand|Select|Wrap|Line Numbers
  1. Dim cmdStr As String
  2. cmdStr = String.Format("insert into homes values('{0}','{1}')", TextBox1.Text, TextBox2.Text)
  3. Dim insert1 As New OleDb.OleDbCommand
  4. insert1 = New OleDb.OleDbCommand(cmdStr,conn)
  5.  
String.Format will replace the {#} with the parameters that follow in order, so {0} will have the value of TextBox1.Text, and {1} will have the value of TextBox2.Text.

Also, I'd suggest that instead of OleDb, you use SqlClient. SqlClient is the native .NET data provider for MS SQL Server. So OleDbConnection becomes SqlConnection (get your connection string here) and OleDbCommand becomes SqlCommand.
Jun 9 '08 #3

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

Similar topics

2
by: Vlado | last post by:
I have db2 7.2 on Win 2000, programing MS VB6.0 I update 1 field on 600 records - successfully, but if i update more then 600 records then i have err. mesage SQL0952N Processing was cancelled...
2
by: cyshao | last post by:
How to reset Router by programing? For some resean, we need usually reset our Router. Now, we have to Reset Router manually(shot down and reopen). Are there any method to control and reset...
13
by: Xah Lee | last post by:
there's this one i can't figure out. I'm trying to kick out image.google.com's top frame when it goes to my page. If you go to http://images.google.com/images?q=milk+tits click on the page...
12
by: Xah Lee | last post by:
Frameset Infinity! http://xahlee.org/js/frame2/frameset.html HTML Frame tutorial + Infinity! http://xahlee.org/js/frame/0.html Xah xah@xahlee.org ∑ http://xahlee.org/
1
by: motiee | last post by:
I'm having a problem with drawing on picturebox in vb.net programing. I draw line(or another shape's) on picturebox, anytime screen refreshes(open dialogbox ro menu,...) the drawn line on picturebox...
2
by: youpak2000 | last post by:
What you can't find in programing text books Professional software development needs more knowledge than language syntax, OOP, styles, etc. There are many things which people usually learn by...
12
by: Xah Lee | last post by:
Of Interest: Introduction to 3D Graphics Programing http://xahlee.org/3d/index.html Currently, this introduction introduces you to the graphics format of Mathematica, and two Java Applet...
15
by: Xah Lee | last post by:
On Java's Interface Xah Lee, 20050223 In Java the language, there's this a keyword “interface”. In a functional language, a function can be specified by its name and parameter specs....
2
by: sengpg345 | last post by:
hi everybody. i have a project in colage for messanger but i haven't idea of socket programing in c#.net . so plz give me the guidence i socket programing. if u have row matirial or tutorial then...
2
by: maamirj | last post by:
Hi, I am newly start prgraming from very beigning using .net c# 2005 can u help me the concepts of programing, oops from begining and how to start programing wih right techniques. thanks
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...

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.