insert message help!

  • Thread starter Thread starter Russ Wittmann
  • Start date Start date
R

Russ Wittmann

I'm working on a small sql project to insert some job numbers, what I need
to do is tell the user in a message box that the insert was either
successful or unsuccessful, I am curious the best way to do this? would I
need to use some if then statements? I would appreciate any help on this.
Right no the code works but I cant figure out how to do a message retuning
successful.


Thank You....

[MY CODE]

'open sql connection...
SqlConn.Open()

'sql insert command(stored proc) & parameters...
SqlInsertCommand1.Parameters("@JobNumber").Value = txtJobNumber.Text

'sql execute command....
SqlInsertCommand1.ExecuteNonQuery()

'close sql connection...
SqlConn.Close()
 
Hi Russ,

Use a try catch block around SqlInsertCommand1.ExecuteNonQuery()
try
SqlInsertCommand1.ExecuteNonQuery()
<here a message that it succeeded>
catch
<here a message that it failed>
end try

HTH,

Bernie Yaeger
 
here is what I have, but one of the problems im having is that if i insert a
blank string it doesn't work because it inputs a blank string in my DB, is
there a way to tell my DB if there is a blank string it is a null?

'open the sql connection...
SqlConn.Open()
'the sql parameters...
SqlInsertCommand1.Parameters("@JobType").Value = txtJobType.Text
'execute the sql command...
Try
SqlInsertCommand1.ExecuteNonQuery()
'set tme message box values...
Dim myokmessage As String
myokmessage = "Your Insert was successfull"
MsgBox(myokmessage, MsgBoxStyle.Information + MsgBoxStyle.OKOnly,
"Information")
Catch
'set tme message box values...
Dim mynomessage As String
mynomessage = Err.Description
MsgBox(mynomessage, MsgBoxStyle.Information + MsgBoxStyle.OKOnly,
"Information")
End Try
'close the sql connection...
SqlConn.Close()

Bernie Yaeger said:
Hi Russ,

Use a try catch block around SqlInsertCommand1.ExecuteNonQuery()
try
SqlInsertCommand1.ExecuteNonQuery()
<here a message that it succeeded>
catch
<here a message that it failed>
end try

HTH,

Bernie Yaeger


Russ Wittmann said:
I'm working on a small sql project to insert some job numbers, what I need
to do is tell the user in a message box that the insert was either
successful or unsuccessful, I am curious the best way to do this? would I
need to use some if then statements? I would appreciate any help on this.
Right no the code works but I cant figure out how to do a message retuning
successful.


Thank You....

[MY CODE]

'open sql connection...
SqlConn.Open()

'sql insert command(stored proc) & parameters...
SqlInsertCommand1.Parameters("@JobNumber").Value = txtJobNumber.Text

'sql execute command....
SqlInsertCommand1.ExecuteNonQuery()

'close sql connection...
SqlConn.Close()
 
How about this

Dim Success as Boolean

Success = ( SqlInsertCommand1.ExecuteNonQuery() >0 )

SqlInsertCommand1.ExecuteNonQuery() will return the number of rows affected

Trapping for an error only tells you if an error occures, not specifically
if an update failed.

Take the instance of "Update MyTable Set Value = 1 Where ID = 5" and no ID=5
exists? No error update is flagged as a success

--
Ibrahim Malluf
http://www.malluf.com
==============================================
MCS Data Services Code Generator
http://64.78.34.175/mcsnet/DSCG/Announcement.aspx
==============================================





Bernie Yaeger said:
Hi Russ,

Use a try catch block around SqlInsertCommand1.ExecuteNonQuery()
try
SqlInsertCommand1.ExecuteNonQuery()
<here a message that it succeeded>
catch
<here a message that it failed>
end try

HTH,

Bernie Yaeger


Russ Wittmann said:
I'm working on a small sql project to insert some job numbers, what I need
to do is tell the user in a message box that the insert was either
successful or unsuccessful, I am curious the best way to do this? would I
need to use some if then statements? I would appreciate any help on this.
Right no the code works but I cant figure out how to do a message retuning
successful.


Thank You....

[MY CODE]

'open sql connection...
SqlConn.Open()

'sql insert command(stored proc) & parameters...
SqlInsertCommand1.Parameters("@JobNumber").Value = txtJobNumber.Text

'sql execute command....
SqlInsertCommand1.ExecuteNonQuery()

'close sql connection...
SqlConn.Close()
 
Hi Russ,

I suggest to Close connection before showing any message box, plus put
connection closing into finally block.
Try
SqlConn.Open()
Try
SqlInsertCommand1.ExecuteNonQuery()
Finally
SqlConn.Close()
End Try
Dim myokmessage As String
myokmessage = "Your Insert was successfull"
MsgBox(myokmessage, MsgBoxStyle.Information + MsgBoxStyle.OKOnly,
catch
bla bla
end try

If you don't you'll db may become locked. (imagine the operator going to
lunch ;) )

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com

Russ Wittmann said:
here is what I have, but one of the problems im having is that if i insert a
blank string it doesn't work because it inputs a blank string in my DB, is
there a way to tell my DB if there is a blank string it is a null?

'open the sql connection...
SqlConn.Open()
'the sql parameters...
SqlInsertCommand1.Parameters("@JobType").Value = txtJobType.Text
'execute the sql command...
Try
SqlInsertCommand1.ExecuteNonQuery()
'set tme message box values...
Dim myokmessage As String
myokmessage = "Your Insert was successfull"
MsgBox(myokmessage, MsgBoxStyle.Information + MsgBoxStyle.OKOnly,
"Information")
Catch
'set tme message box values...
Dim mynomessage As String
mynomessage = Err.Description
MsgBox(mynomessage, MsgBoxStyle.Information + MsgBoxStyle.OKOnly,
"Information")
End Try
'close the sql connection...
SqlConn.Close()

Bernie Yaeger said:
Hi Russ,

Use a try catch block around SqlInsertCommand1.ExecuteNonQuery()
try
SqlInsertCommand1.ExecuteNonQuery()
<here a message that it succeeded>
catch
<here a message that it failed>
end try

HTH,

Bernie Yaeger
would
I
need to use some if then statements? I would appreciate any help on this.
Right no the code works but I cant figure out how to do a message retuning
successful.


Thank You....

[MY CODE]

'open sql connection...
SqlConn.Open()

'sql insert command(stored proc) & parameters...
SqlInsertCommand1.Parameters("@JobNumber").Value = txtJobNumber.Text

'sql execute command....
SqlInsertCommand1.ExecuteNonQuery()

'close sql connection...
SqlConn.Close()
 
it all works but the biggest problem im having is if the user put a blank
string in the text box it inserts in to my db, i need to figure out a way to
make a blank string a null...


Miha Markic said:
Hi Russ,

I suggest to Close connection before showing any message box, plus put
connection closing into finally block.
Try
SqlConn.Open()
Try
SqlInsertCommand1.ExecuteNonQuery()
Finally
SqlConn.Close()
End Try
Dim myokmessage As String
myokmessage = "Your Insert was successfull"
MsgBox(myokmessage, MsgBoxStyle.Information + MsgBoxStyle.OKOnly,
catch
bla bla
end try

If you don't you'll db may become locked. (imagine the operator going to
lunch ;) )

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com

Russ Wittmann said:
here is what I have, but one of the problems im having is that if i
insert
a
blank string it doesn't work because it inputs a blank string in my DB, is
there a way to tell my DB if there is a blank string it is a null?

'open the sql connection...
SqlConn.Open()
'the sql parameters...
SqlInsertCommand1.Parameters("@JobType").Value = txtJobType.Text
'execute the sql command...
Try
SqlInsertCommand1.ExecuteNonQuery()
'set tme message box values...
Dim myokmessage As String
myokmessage = "Your Insert was successfull"
MsgBox(myokmessage, MsgBoxStyle.Information + MsgBoxStyle.OKOnly,
"Information")
Catch
'set tme message box values...
Dim mynomessage As String
mynomessage = Err.Description
MsgBox(mynomessage, MsgBoxStyle.Information + MsgBoxStyle.OKOnly,
"Information")
End Try
'close the sql connection...
SqlConn.Close()

Bernie Yaeger said:
Hi Russ,

Use a try catch block around SqlInsertCommand1.ExecuteNonQuery()
try
SqlInsertCommand1.ExecuteNonQuery()
<here a message that it succeeded>
catch
<here a message that it failed>
end try

HTH,

Bernie Yaeger


"Russ Wittmann" <russ(at)wittmannwebweaving(dot)com> wrote in message
I'm working on a small sql project to insert some job numbers, what
I
need
to do is tell the user in a message box that the insert was either
successful or unsuccessful, I am curious the best way to do this?
would
I
need to use some if then statements? I would appreciate any help on this.
Right no the code works but I cant figure out how to do a message retuning
successful.


Thank You....

[MY CODE]

'open sql connection...
SqlConn.Open()

'sql insert command(stored proc) & parameters...
SqlInsertCommand1.Parameters("@JobNumber").Value = txtJobNumber.Text

'sql execute command....
SqlInsertCommand1.ExecuteNonQuery()

'close sql connection...
SqlConn.Close()
 
SqlInsertCommand1.Parameters("@JobType").Value =
Iif(txtJobType.Text.Trim().Length = 0, DBNull.Value, txtJobType.Text)

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com


Russ Wittmann said:
it all works but the biggest problem im having is if the user put a blank
string in the text box it inserts in to my db, i need to figure out a way to
make a blank string a null...


Miha Markic said:
Hi Russ,

I suggest to Close connection before showing any message box, plus put
connection closing into finally block.
Try
SqlConn.Open()
Try
SqlInsertCommand1.ExecuteNonQuery()
Finally
SqlConn.Close()
End Try
Dim myokmessage As String
myokmessage = "Your Insert was successfull"
MsgBox(myokmessage, MsgBoxStyle.Information + MsgBoxStyle.OKOnly,
catch
bla bla
end try

If you don't you'll db may become locked. (imagine the operator going to
lunch ;) )

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com

insert
DB,
what
I
need
to do is tell the user in a message box that the insert was either
successful or unsuccessful, I am curious the best way to do this? would
I
need to use some if then statements? I would appreciate any help on
this.
Right no the code works but I cant figure out how to do a message
retuning
successful.


Thank You....

[MY CODE]

'open sql connection...
SqlConn.Open()

'sql insert command(stored proc) & parameters...
SqlInsertCommand1.Parameters("@JobNumber").Value = txtJobNumber.Text

'sql execute command....
SqlInsertCommand1.ExecuteNonQuery()

'close sql connection...
SqlConn.Close()
 
worked like a charm....


Miha Markic said:
SqlInsertCommand1.Parameters("@JobType").Value =
Iif(txtJobType.Text.Trim().Length = 0, DBNull.Value, txtJobType.Text)

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com


Russ Wittmann said:
it all works but the biggest problem im having is if the user put a blank
string in the text box it inserts in to my db, i need to figure out a
way
to
make a blank string a null...


DB, what
help
on
this.
Right no the code works but I cant figure out how to do a message
retuning
successful.


Thank You....

[MY CODE]

'open sql connection...
SqlConn.Open()

'sql insert command(stored proc) & parameters...
SqlInsertCommand1.Parameters("@JobNumber").Value = txtJobNumber.Text

'sql execute command....
SqlInsertCommand1.ExecuteNonQuery()

'close sql connection...
SqlConn.Close()
 
Back
Top