8 Replies - 442 Views - Last Post: 16 May 2012 - 12:16 PM Rate Topic: -----

#1 Shay6o0ona  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 02-May 12

Error 26 in Add button

Posted 16 May 2012 - 03:46 AM

iam use VB.NET 2005 and my Database in SQL server2005.
and i want to add button used to save the database from VB to SQL
but i have Error in this code and i dont know where :helpsmilie:

Public Class Form1
    Dim cnn As New SqlClient.SqlConnection

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.EMPTableAdapter.Fill(Me.TestDataSet.EMP)
        cnn = New SqlClient.SqlConnection
        cnn.ConnectionString = "Data Source=" & Application.StartupPath & "\--\sql2005;Initial Catalog=Test1;Integrated Security=True"

    End Sub
    Private Sub RefreshData()
        If Not cnn.State = ConnectionState.Open Then
            cnn.Open()
        End If

        Dim da As New SqlClient.SqlDataAdapter("SELECT ID," & _
                                                " Name, Age, Gender" & _
                                                " FROM EMP ORDER BY ID ", cnn)
        da.Fill(TestDataSet.EMP)

        cnn.Close()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim cmd As New SqlClient.SqlCommand

        If Not cnn.State = ConnectionState.Open Then
            cnn.Open()
        End If

        cmd.Connection = cnn
        cmd.CommandText = " INSERT INTO Form1 (ID, Name, Age, Gender )" & _
        "VALUES (" & Me.TextBox1.Text & "," & Me.TextBox2.Text & "," & Me.TextBox3.Text & "," & _
        Me.ComboBox1.Text & ")"

        cmd.ExecuteNonQuery()

        RefreshData()

        cnn.Close()

    End Sub
End Class



Is This A Good Question/Topic? 0
  • +

Replies To: Error 26 in Add button

#2 sela007  Icon User is offline

  • D.I.C Addict

Reputation: 137
  • View blog
  • Posts: 829
  • Joined: 21-December 11

Re: Error 26 in Add button

Posted 16 May 2012 - 05:21 AM

what is the error message?
Was This Post Helpful? 0
  • +
  • -

#3 sela007  Icon User is offline

  • D.I.C Addict

Reputation: 137
  • View blog
  • Posts: 829
  • Joined: 21-December 11

Re: Error 26 in Add button

Posted 16 May 2012 - 05:30 AM

if you don't know where is the error, learn how to use debugging
Was This Post Helpful? 0
  • +
  • -

#4 Shay6o0ona  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 02-May 12

Re: Error 26 in Add button

Posted 16 May 2012 - 07:00 AM

Attached Image

This is The Error
Was This Post Helpful? 0
  • +
  • -

#5 Celerian  Icon User is offline

  • D.I.C Regular


Reputation: 144
  • View blog
  • Posts: 384
  • Joined: 30-March 12

Re: Error 26 in Add button

Posted 16 May 2012 - 07:04 AM

That error is not coming from the code you posted. Somewhere you should have code for cnn.Open that we could see and tell you why your connection cannot be opened. Chances are, it is not being built correctly.
Was This Post Helpful? 0
  • +
  • -

#6 sela007  Icon User is offline

  • D.I.C Addict

Reputation: 137
  • View blog
  • Posts: 829
  • Joined: 21-December 11

Re: Error 26 in Add button

Posted 16 May 2012 - 07:06 AM

i think connection string is not valid

This post has been edited by sela007: 16 May 2012 - 07:08 AM

Was This Post Helpful? 0
  • +
  • -

#7 Shay6o0ona  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 02-May 12

Re: Error 26 in Add button

Posted 16 May 2012 - 11:25 AM

View PostCelerian, on 16 May 2012 - 07:04 AM, said:

That error is not coming from the code you posted. Somewhere you should have code for cnn.Open that we could see and tell you why your connection cannot be opened. Chances are, it is not being built correctly.



what you want to see???
Was This Post Helpful? 0
  • +
  • -

#8 Shay6o0ona  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 02-May 12

Re: Error 26 in Add button

Posted 16 May 2012 - 11:37 AM

View Postsela007, on 16 May 2012 - 07:06 AM, said:

i think connection string is not valid



no i check it
Was This Post Helpful? 0
  • +
  • -

#9 sela007  Icon User is offline

  • D.I.C Addict

Reputation: 137
  • View blog
  • Posts: 829
  • Joined: 21-December 11

Re: Error 26 in Add button

Posted 16 May 2012 - 12:16 PM

just type your error message in google, there are lot of explanations how resolve that problem, and where the problem can be.
Look at this:
link 1,
link 2,
hope this will help
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1