Click here to Skip to main content
15,881,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Private Sub AddStocksInUpdating()
        If txtItemNo.Text = "" Then
            MsgBox("Please select item to add stocks.", MsgBoxStyle.Critical, "Select Item")
            Exit Sub
        End If
        Dim strStocksIn As String

        strStocksIn = InputBox("Enter number of items : ", "Stocks In")
        txtQuantity.Text = Val(txtQuantity.Text) + Val(strStocksIn)
        Try
            sqL = "INSERT INTO StocksIn(ItemNo, ItemQuantity, SIDate, CurrentStocks) VALUES('" & txtItemNo.Text & "', '" & strStocksIn & "', '" & Format(Date.Now, "Short Date") & "', " & txtQuantity.Text & ")"
            ConnDB()
            cmd = New OleDbCommand(sqL, conn)
            Dim i As Integer

            i = cmd.ExecuteNonQuery()
            If i > 0 Then
                MsgBox("Stocks added successfully", MsgBoxStyle.Information, "Stocks In")
                Updateproduct()
            End If
        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            cmd.Dispose()
            conn.Close()
        End Try
    End Sub
Posted
Comments
hansoctantan 11-Apr-14 5:46am    
this question is the same as this
http://www.codeproject.com/Questions/758205/How-can-change-it-in-Csharp
Member 10720633 11-Apr-14 5:46am    
yeah i did but its always have error


private void AddStocksInUpdating()
{
if (string.IsNullOrEmpty(txtItemNo.Text)) {
Interaction.MsgBox("Please select item to add stocks.", MsgBoxStyle.Critical, "Select Item");
return;
}
string strStocksIn = null;

strStocksIn = Interaction.InputBox("Enter number of items : ", "Stocks In");
txtQuantity.Text = Conversion.Val(txtQuantity.Text) + Conversion.Val(strStocksIn);
try {
System.Data.sqL = "INSERT INTO StocksIn(ItemNo, ItemQuantity, SIDate, CurrentStocks) VALUES('" + txtItemNo.Text + "', '" + strStocksIn + "', '" + Strings.Format(System.DateTime.Now, "Short Date") + "', " + txtQuantity.Text + ")";
ConnDB();
cmd = new OleDbCommand(System.Data.sqL, conn);
int i = 0;

i = cmd.ExecuteNonQuery();
if (i > 0) {
Interaction.MsgBox("Stocks added successfully", MsgBoxStyle.Information, "Stocks In");
Updateproduct();
}
} catch (Exception ex) {
Interaction.MsgBox(ex.Message);
} finally {
cmd.Dispose();
conn.Close();
}
}

1 solution

That isn't C# - it VB.
It won't compile as C#, or even close.
But...you could run it through this: http://www.developerfusion.com/tools/convert/vb-to-csharp/[^] - it's an online code translater that mostly does a pretty good job...
 
Share this answer
 
Comments
Member 10720633 11-Apr-14 5:49am    
yeah i did
private void AddStocksInUpdating()
{
if (string.IsNullOrEmpty(txtItemNo.Text)) {
Interaction.MsgBox("Please select item to add stocks.", MsgBoxStyle.Critical, "Select Item");
return;
}
string strStocksIn = null;

strStocksIn = Interaction.InputBox("Enter number of items : ", "Stocks In");
txtQuantity.Text = Conversion.Val(txtQuantity.Text) + Conversion.Val(strStocksIn);
try {
System.Data.sqL = "INSERT INTO StocksIn(ItemNo, ItemQuantity, SIDate, CurrentStocks) VALUES('" + txtItemNo.Text + "', '" + strStocksIn + "', '" + Strings.Format(System.DateTime.Now, "Short Date") + "', " + txtQuantity.Text + ")";
ConnDB();
cmd = new OleDbCommand(System.Data.sqL, conn);
int i = 0;

i = cmd.ExecuteNonQuery();
if (i > 0) {
Interaction.MsgBox("Stocks added successfully", MsgBoxStyle.Information, "Stocks In");
Updateproduct();
}
} catch (Exception ex) {
Interaction.MsgBox(ex.Message);
} finally {
cmd.Dispose();
conn.Close();
}
}
OriginalGriff 11-Apr-14 6:15am    
Well, start with the first error, and fix it! :laugh:
Look at the code in C#, not VB and remember: C# is case sensitive, VB isn't. So "Sql" is different to "sqL" and C# will not recognise it.
The first error you will get is that 'sqL' is not found - because it should be 'Sql' instead.
So fix that, and look at the next error. Then repeat! :laugh:
Member 10720633 11-Apr-14 6:22am    
yeah i know no but solve this statement probs.

if (string.IsNullOrEmpty(txtItemNo.Text))
{
Interaction.MsgBox("Please select item to add stocks.", MsgBoxStyle.Critical, "Select Item"); return;
}
string strStocksIn = null; strStocksIn = Interaction.InputBox("Enter number of items : ", "Stocks In"); txtQuantity.Text = Conversion.Val(txtQuantity.Text) + Conversion.Val(strStocksIn);
OriginalGriff 11-Apr-14 6:52am    
Replace Interaction.MsgBox with MessageBox.Show, and adjust the parameters appropriately.
It's not difficult if you have any knowledge of .NET - this is basic stuff! :laugh:

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