hello there... acctually i m creating a desktop application in vb.net so on the data insertaton page i had got an error that is "the ConnectionString property not initilized".. so i m posting all my code here... kindly help me..

Public Class Registration

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim con_str As String = "Data Source=.\SQLEXPRESS;Initial Catalog=data;Integrated Security=True"
        Dim cmd As New SqlCommand()
        Dim con As New SqlConnection()
        cmd.CommandText = "INSERT into reg(name,uname,pass,year,branch,scholar,email,add) values (@a,@b,@c,@d,@e,@f,@g,@h)"
        cmd.Connection = con
        cmd.Parameters.Add("@a", t1.Text)
        cmd.Parameters.Add("@b", t2.Text)
        cmd.Parameters.Add("@c", t3.Text)
        cmd.Parameters.Add("@d", t4.Text)
        cmd.Parameters.Add("@e", t5.Text)
        cmd.Parameters.Add("@f", t6.Text)
        cmd.Parameters.Add("@g", t7.Text)
        cmd.Parameters.Add("@h", rt.Text)

       

        Dim dd As New SqlDataAdapter(cmd)
        Dim dst As New DataSet()
        Using (dd)
            dd.Fill(dst, "reg")
        End Using
    End Sub

End Class

Recommended Answers

All 11 Replies

Hi

Try inserting these lines:
Before you execute the cmd

If con.State = ConnectionState.Closed Then
  con.open
end if

at the end sub

If con.State = ConnectionState.Open Then
  con.Close
end if

Thats not working still that same message shown .... Pls give some other help ...

Hi

Are you getting the same error?

Anyway I've just noticed that you are using an Insert Query to try and fill a dataset table - this wont work

Inserts do exactly that, they insert data and they do not return recordsets. You need to use a SELECT statement.

i dont want to retrive data so why should i use SELECT statement,,, i just want to insert data so that i hd use INSERT....

if you are trying to insert a record into the database then try this:

Dim con_str As String = "Data Source=.\SQLEXPRESS;Initial Catalog=data;Integrated Security=True"
Dim cmd As New SqlCommand()        
Dim con As New SqlConnection()
con.ConnectionString =con_str

cmd.CommandText = "INSERT into reg(name,uname,pass,year,branch,scholar,email,add) values (@a,@b,@c,@d,@e,@f,@g,@h)"
cmd.Connection = con        
cmd.Parameters.Add("@a", t1.Text)        
cmd.Parameters.Add("@b", t2.Text)
cmd.Parameters.Add("@c", t3.Text)
cmd.Parameters.Add("@d", t4.Text)        
cmd.Parameters.Add("@e", t5.Text)        
cmd.Parameters.Add("@f", t6.Text)        
cmd.Parameters.Add("@g", t7.Text)        
cmd.Parameters.Add("@h", rt.Text)

if con.State = ConnectionState.Closed then
  con.open()
end if
cmd.Execute()
if con.State = ConnectionState.Open then con.Close

No need for dataset etc if you don't want to see the data....

i m listing u files in solution explorer... pls tell me any other file requires in solution explorer.. because... now i dnt think that any more errors remaining in .. code.. also tell u i had set dsn as default database...
items in solution explorer..
1) My Project
2) app.config
3) dataDataset.xsd
4) Registration.vb
there is no database file in it...
database is in server explorer...

i m implimenting ur code too then also m bearing the same problem

use this connection string

Dim con_str As String = "Data Source=SQLEXPRESS;Initial Catalog=data;Integrated Security=True"

dear while you r using adapter not specifying connection object try this

1.
      Public Class Registration
   2.
       
   3.
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
   4.
      Dim con_str As String = "Data Source=.\SQLEXPRESS;Initial Catalog=data;Integrated Security=True"
   5.
      Dim cmd As New SqlCommand()
   6.
      Dim con As New SqlConnection(con_str)
   7.
      cmd.CommandText = "INSERT into reg(name,uname,pass,year,branch,scholar,email,add) values (@a,@b,@c,@d,@e,@f,@g,@h)"
   8.
      cmd.Connection = con
   9.
      cmd.Parameters.Add("@a", t1.Text)
  10.
      cmd.Parameters.Add("@b", t2.Text)
  11.
      cmd.Parameters.Add("@c", t3.Text)
  12.
      cmd.Parameters.Add("@d", t4.Text)
  13.
      cmd.Parameters.Add("@e", t5.Text)
  14.
      cmd.Parameters.Add("@f", t6.Text)
  15.
      cmd.Parameters.Add("@g", t7.Text)
  16.
      cmd.Parameters.Add("@h", rt.Text)
  17.
       
  18.
       
  19.
       
  20.
      Dim dd As New SqlDataAdapter(cmd,con)
  21.
      Dim dst As New DataSet()
  22.
      Using (dd)
  23.
      dd.Fill(dst, "reg")
  24.
      End Using
  25.
      End Sub

Hi,

Your connection string looks ok to me, try checking it here:http://www.connectionStrings.com

The only other thing I can think of is the database.

Is it definately a local SQL express database and is SQL running (check under services)?

What user does your app run under? and does this user have the correct permissions on the database? Instead of using the trusted connection, if you specify the user does that work?

i hd tried this 1 also... bt still nt workin for me.... now what could be the solution for this .... ??? god knows.... also thought there must be some machine kind of problem...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.