Click here to Skip to main content
15,921,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When i insert a data
i want to display a message as
do you want to save
as YES or NO
if i press Yes
i can save otherwise no

i need like this
when i use messagebuttons it will be saving when i press no but also its saving

VB
Dim con As New SqlConnection
       con.ConnectionString = "Data Source=192.168.1.7;Initial Catalog=ACC_FG;User ID=sa;Password=sql"
       Dim cmd As New SqlCommand
       cmd.Connection = con
       Try

           cmd = New SqlCommand("insert into subledger (number,[desc]) values ('" & TextBox1.Text & "','" & TextBox2.Text & "') ", con)

           Try
               MessageBox.Show("Want to Save", "title", MessageBoxButtons.YesNo)
               con.Open()
               cmd.ExecuteNonQuery()
               con.Close()
           Catch
               MessageBox.Show("not saved")
           End Try


       Catch ex As Exception
           MessageBox.Show("NOT SAVED CHECKED BY ADMINISTRATOR")
       End Try
Posted
Updated 1-Jan-14 20:44pm
v2
Comments
thatraja 2-Jan-14 2:43am    
Delete this question. I have answered in your previous question
shakeer mp 2-Jan-14 2:57am    
can u please send me the answer as soon as possible

Here a sample, complete yourself.
VB
DialogResult result1 = MessageBox.Show("Want to save?", "Save",	MessageBoxButtons.YesNo)
If result1 = DialogResult.Yes Then
'Do your operation

''Else'Optional to display another messagebox if you choose No
''Do else operation
End If
 
Share this answer
 
v2
Comments
shakeer mp 2-Jan-14 3:15am    
DialogResult res = MessageBox.Show("want to save?", "SAVE", MessageBoxButtons.YesNo)
when i type this and enter i will be display like this
DialogResult(res = MessageBox.Show("want to save?", "SAVE", MessageBoxButtons.YesNo))
thatraja 2-Jan-14 3:18am    
that's ok. I'm not a VB guy(so don't know much about VB syntax). Just check it out.
shakeer mp 2-Jan-14 3:22am    
thanks i cleared .....
thanks a lot
thatraja 2-Jan-14 3:25am    
Welcome.
check this:-
VB
Dim result = MessageBox.Show("Want to save?","Save", MessageBoxButtons.YesNo)
If result = DialogResult.Yes Then
con.Open()
               cmd.ExecuteNonQuery()
               con.Close()
End If
 
Share this answer
 
Comments
shakeer mp 2-Jan-14 7:48am    
how can i do combox data binding through database in vb
i am also new to vb I know in c# please help me

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