Click here to Skip to main content
15,346,335 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: How can my app look the same on all machines? Pin
Dave Kreskowiak10-Dec-19 4:59
mveDave Kreskowiak10-Dec-19 4:59 
AnswerRe: How can my app look the same on all machines? Pin
Gerry Schmitz10-Dec-19 8:14
mveGerry Schmitz10-Dec-19 8:14 
QuestionHow can I get an free installer that registers .dll and .ocx components as I install my app? Pin
Member 146743679-Dec-19 14:17
MemberMember 146743679-Dec-19 14:17 
AnswerRe: How can I get an free installer that registers .dll and .ocx components as I install my app? Pin
CHill6010-Dec-19 1:44
mveCHill6010-Dec-19 1:44 
AnswerRe: How can I get an free installer that registers .dll and .ocx components as I install my app? Pin
gvidali7-Feb-20 3:09
Membergvidali7-Feb-20 3:09 
Question[Solved] - How to retrieve value inserted to variable Pin
nrdroque5-Dec-19 23:26
Membernrdroque5-Dec-19 23:26 
AnswerRe: How to retrieve value inserted to variable Pin
dan!sh 6-Dec-19 0:41
professional dan!sh 6-Dec-19 0:41 
AnswerRe: How to retrieve value inserted to variable Pin
Richard Deeming6-Dec-19 1:05
mveRichard Deeming6-Dec-19 1:05 
Member 14668666 wrote:
VB.NET
serialnumber = sql_query.ExecuteScalar()

Try
    If sql_query.ExecuteScalar() <> 0 Then
NB: You're executing the INSERT query twice every time you call this method.

Also, ExecuteScalar won't have anything to return, since your query doesn't return any records.

Add an OUTPUT clause[^] to your query:
VB.NET
sql_query.CommandText = "INSERT INTO etiquetas WITH (tablockx) (nome_posto, data, lote, serialnumber, partnumber, versao, indexnumber, semana, qrgerado, operador, snpn, posx, posy, impressora) OUTPUT inserted.serialnumber SELECT TOP (1) @posto, @data, @lote, T.x, @partnumber, @versao, @indexnumber, @semana, T.x + @partnumber + @versao + @indexnumber + @semana, @operador, T.x + @partnumber, @posx, @posy, @ip_impressora FROM [etiquetas] x CROSS APPLY (VALUES(format(convert(int, x.serialnumber) + 1, '0000000'))) T(x) WHERE partnumber LIKE @partnumber ORDER BY id DESC;"
Remove the @sn parameter, since it's not used in the query.

Change your code so that it only executes the query once.
VB.NET
' Remove this line:
' sql_query.Parameters.AddWithValue("@sn", serialnumber)

' Remove this line:
' serialnumber = sql_query.ExecuteScalar()

Try
    serialnumber = sql_query.ExecuteScalar()
Catch ex As Exception
    IO.File.AppendAllText("C:\ti\Log.txt", String.Format("{0}{1}", Environment.NewLine, Now() + " - " + ex.ToString()))
End Try




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

GeneralRe: How to retrieve value inserted to variable Pin
nrdroque6-Dec-19 3:40
Membernrdroque6-Dec-19 3:40 
GeneralRe: How to retrieve value inserted to variable Pin
Eddy Vluggen6-Dec-19 8:49
professionalEddy Vluggen6-Dec-19 8:49 
QuestionMS Chart is adding extra X axis when doing multiple series. Pin
Member 1435926026-Nov-19 8:31
MemberMember 1435926026-Nov-19 8:31 
QuestionHow to determine specific object from Msg.HWnd 'MESSAGE CLOSED' Pin
mo149225-Nov-19 2:32
Membermo149225-Nov-19 2:32 
AnswerRe: can not find the pin Pin
Richard MacCutchan17-Nov-19 21:17
mveRichard MacCutchan17-Nov-19 21:17 
Questiongroup by name for sum amount Pin
Member 1332257413-Nov-19 19:39
MemberMember 1332257413-Nov-19 19:39 
AnswerRe: group by name for sum amount Pin
Dave Kreskowiak14-Nov-19 2:40
mveDave Kreskowiak14-Nov-19 2:40 
Questioncode project data base Pin
abuahmed20191-Nov-19 4:24
Memberabuahmed20191-Nov-19 4:24 
AnswerRe: code project data base Pin
Dave Kreskowiak1-Nov-19 5:00
mveDave Kreskowiak1-Nov-19 5:00 
QuestionSystem.IO.IOException HResult=0x80131620 When using NetworkStream.Read function Pin
fd975029-Oct-19 22:48
professionalfd975029-Oct-19 22:48 
AnswerRe: System.IO.IOException HResult=0x80131620 When using NetworkStream.Read function Pin
Richard MacCutchan29-Oct-19 23:09
mveRichard MacCutchan29-Oct-19 23:09 
GeneralRe: System.IO.IOException HResult=0x80131620 When using NetworkStream.Read function Pin
fd975029-Oct-19 23:23
professionalfd975029-Oct-19 23:23 
GeneralRe: System.IO.IOException HResult=0x80131620 When using NetworkStream.Read function Pin
fd975030-Oct-19 0:02
professionalfd975030-Oct-19 0:02 
QuestionHow to solve problem with datagrid and tabcontrol(vb.net) Pin
Member 1447080727-Oct-19 22:52
MemberMember 1447080727-Oct-19 22:52 
AnswerRe: How to solve problem with datagrid and tabcontrol(vb.net) Pin
Richard MacCutchan27-Oct-19 23:14
mveRichard MacCutchan27-Oct-19 23:14 
GeneralRe: How to solve problem with datagrid and tabcontrol(vb.net) Pin
Member 1447080730-Oct-19 17:33
MemberMember 1447080730-Oct-19 17:33 
GeneralRe: How to solve problem with datagrid and tabcontrol(vb.net) Pin
Richard MacCutchan30-Oct-19 22:58
mveRichard MacCutchan30-Oct-19 22:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.