TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Dejan Dejanovic
NA
15
16.3k
Vb.net Code For Executing Sql Query. Need Someone To Check The Code!
Dec 31 2010 7:50 AM
Hello VbDotHeaven,
So far I have learn some basics. I`m now at the point calling server from vb.net, and run query inside vb.net code.
I have write two codes on button click. One button is checked server connection, other should execute query for server table.
Connection code is working, as I have set two messages, and getting successfull message.
Second code is not working, as nothing happened when press button.
Sql statement is very simple, and it works if I run it manually.
So, need someone to check below firs Privat Sub code, or and give me some helpful tips.
Imports System.Data.SqlClient
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim SQLCONN As New SqlConnection
Dim SQLCMD As New SqlCommand
SQLCONN.ConnectionString = "Server=DEJANC-PC\SQLEXPRESS;Database=TEST;Integrated security=True"
SQLCONN.Open()
SQLCMD.Connection = SQLCONN
SQLCMD.CommandType = CommandType.Text
SQLCMD.CommandText = "DELETE FROM TABLE1"
SQLCMD.ExecuteNonQuery()
SQLCONN.Close()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim sqlconn As New SqlConnection
sqlconn.ConnectionString = "Server=DEJANC-PC\SQLEXPRESS;Database=TEST;Integrated security=True"
Try
sqlconn.Open()
Catch ex As Exception
MessageBox.Show("Error while connecting to sql server." & ex.Message)
End Try
If sqlconn.State = 1 Then
MessageBox.Show("Successfull")
End If
End Sub
Thank you in advance to anyone for help!
Reply
Answers (
1
)
how to get the datagrid cell value of selected row.
How do I customize the message box?