Click here to Skip to main content
14,699,609 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
i want to add data in sql server table from application,my code block is

Imports System.Data.SqlClient
Imports System.Data.SqlClient.SqlConnection

Public Class Form1
    Dim cn As SqlConnection

    Dim ConStr As String
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ConStr = "Data Source=ANAND-PC\SQLEXPRESS;Initial Catalog=anand;User ID=;Password="
        cn = New SqlConnection(ConStr)

    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
        Dim query As String
        query = "Insert Into anand1 (roll) values (" & TextBox1.Text & ");"

        cmd.CommandText = query
        cmd.CommandType = CommandType.Text
        cmd.Connection = cn




    End Sub
End Class

it is showing some error in

please help its very urgent
Updated 16-Apr-12 11:39am
ZurdoDev 16-Apr-12 15:19pm
If you want help in a hurry, maybe the error message would be useful to us.
Nelek 16-Apr-12 16:40pm
Code tags added. Saying that is urgent won't help you to get a fast answer. People here help for free in spare time. You should respect that.

1 solution

modify your connection string ,provide user id and password!!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900