How can I solve "Must declare the scalar variable #cds" sql? - sql

For the last three hours. I searched the internet for solutions to my problem. I found some but none of them worked (!?). The error is in the btnAdd Sub. I couldn't use this form of declaration: 'DECLARE #cds SqlDBType.SmallInt because I would get the following error: Statement is not valid inside a method/multiline lambda. I also used their form of declaration http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.insertcommand%28v=vs.110%29.aspx but again... I receive the same error. The commented sections are everything I tried. Maybe you can help me solve this. :)
Updated correct solution:
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
con.Open()
Dim dr As DataRow
mycmd.CommandText = "insert into studenti(cods, nrmatricol, nume, grupa, datan) values(#cs,#nm,#n,#g,#dn)"
Dim p1 As New SqlParameter
Dim p2 As New SqlParameter
Dim p3 As New SqlParameter
Dim p4 As New SqlParameter
Dim p5 As New SqlParameter
mycmd.Parameters.Clear()
p1.ParameterName = "#cs"
p1.Value = Convert.ToInt16(txtCodS.Text)
mycmd.Parameters.Add(p1)
p2.ParameterName = "#nm"
p2.Value = txtNrMat.Text
mycmd.Parameters.Add(p2)
p3.ParameterName = "#n"
p3.Value = txtNume.Text
mycmd.Parameters.Add(p3)
p4.ParameterName = "#g"
p4.Value = txtGrupa.Text
mycmd.Parameters.Add(p4)
p5.ParameterName = "#dn"
p5.Value = Convert.ToDateTime(txtDataN.Text)
mycmd.Parameters.Add(p5)
mycmd.Connection = con
da1.InsertCommand = mycmd
dr = DataSet1.Tables("studenti").NewRow()
dr("cods") = Convert.ToInt16(txtCodS.Text)
dr("nrmatricol") = txtNrMat.Text
dr("nume") = txtNume.Text
dr("grupa") = txtGrupa.Text
dr("datan") = Convert.ToDateTime(txtDataN.Text)
DataSet1.Tables("studenti").Rows.Add(dr)
da1.Update(DataSet1, "studenti")
UpdateUI()
con.Close()
End Sub
Wrong:
Dim da1 As New SqlClient.SqlDataAdapter
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
con.Open()
Dim dr As DataRow
Dim mycmd As New SqlClient.SqlCommand
//Dim mycmd2 As New SqlClient.SqlCommand
//mycmd2.Connection = con
// mycmd2.CommandText = "select* from studenti"
//Dim v(4) As Object
//v(0) = Convert.ToInt16(txtCodS.Text)
//v(1) = txtNrMat.Text
//v(2) = txtNume.Text
//v(3) = txtGrupa.Text
// v(4) = txtDataN.Text
mycmd.CommandText = "insert into studenti (cods,nrmatricol,nume,grupa,datan) values (#cds,#nm,#n,#g,#dn)"
Dim p1 As New SqlClient.SqlParameter
p1.ParameterName = "#cds"
p1.Value = Convert.ToInt16(txtCodS.Text)
//DECLARE #cds SqlDBType.SmallInt
//cmd.Parameters.Clear()
cmd.Parameters.Add(p1)
//cmd.Parameters.Add("#cds", SqlDbType.SmallInt).Value = Convert.ToInt16(txtCodS.Text)
cmd.Parameters.Add("#nm", SqlDbType.VarChar, 10)
cmd.Parameters.Add("#n", SqlDbType.VarChar, 30)
cmd.Parameters.Add("#g", SqlDbType.VarChar, 10)
cmd.Parameters.Add("#dn", SqlDbType.DateTime)
mycmd.Connection = con
da1.InsertCommand = mycmd
dr = DataSet1.Tables("studenti").NewRow()
dr("cods") = Convert.ToInt16(txtCodS.Text)
dr("nrmatricol") = txtNrMat.Text
dr("nume") = txtNume.Text
dr("grupa") = txtGrupa.Text
dr("datan") = Convert.ToDateTime(txtDataN.Text)
DataSet1.Tables("studenti").Rows.Add(dr)
da1.Update(DataSet1, "studenti")
UpdateUI()
con.Close()
End Sub
End Class

#cds variable is set by after that it is removed by cmd.Parameters.Clear().
Just remove this line of code and provide a value for #cds.

Related

asp.net vb Button.click insert to sql working at client but not working when move to server

This code is working a PC. I have filled grid view with the dataset, so I suppose I can read Excel.
However, the insert to sql part is not working when I copy the code to the server and I don't know why. It is not throwing any errors.
I removed the try catch lines but still, there are no errors.
I am adding new code block, I did a test and wrote a siple insert code like;
Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim mysql_connection As New SqlConnection
mysql_connection.ConnectionString = "Data Source=SRV01;Initial Catalog=TR_Development;Persist Security Info=True;User ID=sa"
Dim command As String = "insert into gez_test (test) values ('c')"
Dim mysqlcommand As New SqlCommand
mysqlcommand.CommandType = CommandType.Text
mysqlcommand.CommandText = command
mysqlcommand.Connection = mysql_connection
If mysql_connection.State = ConnectionState.Closed Then mysql_connection.Open()
mysqlcommand.ExecuteNonQuery()
If mysql_connection.State = ConnectionState.Open Then mysql_connection.Close()
End Sub
And at server it is not inserting. What can be the problem any idea?
Orginal code
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Dim path_ As String = "\\exchange\COMPANY\web\" + FileUpload1.FileName
FileUpload1.PostedFile.SaveAs(path_)
Dim identifier As Boolean = False
Dim connStr As String = "provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + path_ + "';Extended Properties=Excel 12.0;"
Dim MyConnection As OleDbConnection
Dim ds As DataSet
Dim MyCommand As OleDbDataAdapter
MyConnection = New OleDbConnection(connStr)
MyConnection.Open()
Dim dtSheets As DataTable = MyConnection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing)
Dim listSheet As New List(Of String)
Dim drSheet As DataRow
For Each drSheet In dtSheets.Rows
listSheet.Add(drSheet("TABLE_NAME").ToString())
Next
For Each sheet As String In listSheet
If sheet = "'BAS+Surcharges$'" Then
identifier = True
Exit For
End If
Next
If identifier = True Then
MyCommand = New OleDbDataAdapter("select * from [BAS+Surcharges$]", MyConnection)
ds = New System.Data.DataSet()
MyCommand.Fill(ds)
MyConnection.Close()
'**************SQL***************
Dim line, columns As Integer
line = ds.Tables(0).Rows.Count
columns = ds.Tables(0).Columns.Count
Label1.Text = line.ToString
ASPxTextBox1.Text = line.ToString
If line > 0 And columns = 16 Then
Dim command As String = "exec SP_INTRA_EXCEL_LINE_INSERT" _
+ " #line_isim, #nereden, #via, #nereye, #transit_sure, #baslangic_tarihi," _
+ "#e_kadar_gecerli, #kalem_kodu, #fiyatlandirma, #20DRY, #40DRY, #40HDRY," _
+ "#40HREF_NOR, #kayit_eden"
Dim mysql_connection As New SqlConnection
mysql_connection.ConnectionString = ConfigurationManager.ConnectionStrings("TR_DevelopmentConnectionString").ConnectionString
Dim mysqlcommand As New SqlCommand
mysqlcommand.CommandType = CommandType.Text
mysqlcommand.CommandText = command
mysqlcommand.Connection = mysql_connection
Dim line_isim, nereden, via, nereye, transit_sure, baslangic_tarihi, e_kadar_gecerli,
kalem_kodu, fiyatlandirma, _20DRY, _40DRY, _40HDRY,
_40HREF_NOR, kayit_eden As String
If mysql_connection.State = ConnectionState.Closed Then mysql_connection.Open()
For i = 6 To line - 1
line_isim = ds.Tables(0).Rows(i).Item(13).ToString
nereden = ds.Tables(0).Rows(i).Item(0).ToString
via = ds.Tables(0).Rows(i).Item(14).ToString
nereye = ds.Tables(0).Rows(i).Item(1).ToString
transit_sure = ds.Tables(0).Rows(i).Item(15).ToString
baslangic_tarihi = Convert.ToDateTime(ds.Tables(0).Rows(i).Item(2).ToString).ToString
e_kadar_gecerli = Convert.ToDateTime(ds.Tables(0).Rows(i).Item(3).ToString).ToString
kalem_kodu = ds.Tables(0).Rows(i).Item(7).ToString
fiyatlandirma = ds.Tables(0).Rows(i).Item(8).ToString
_20DRY = ds.Tables(0).Rows(i).Item(9).ToString
_40DRY = ds.Tables(0).Rows(i).Item(10).ToString
_40HDRY = ds.Tables(0).Rows(i).Item(11).ToString
_40HREF_NOR = ds.Tables(0).Rows(i).Item(12).ToString
kayit_eden = Environment.UserName.ToString
mysqlcommand.Parameters.AddWithValue("#line_isim", line_isim)
mysqlcommand.Parameters.AddWithValue("#nereden", nereden)
mysqlcommand.Parameters.AddWithValue("#via", via)
mysqlcommand.Parameters.AddWithValue("#nereye", nereye)
mysqlcommand.Parameters.AddWithValue("#transit_sure", transit_sure)
mysqlcommand.Parameters.AddWithValue("#baslangic_tarihi", baslangic_tarihi)
mysqlcommand.Parameters.AddWithValue("#e_kadar_gecerli", e_kadar_gecerli)
mysqlcommand.Parameters.AddWithValue("#kalem_kodu", kalem_kodu)
mysqlcommand.Parameters.AddWithValue("#fiyatlandirma", fiyatlandirma)
mysqlcommand.Parameters.AddWithValue("#20DRY", _20DRY)
mysqlcommand.Parameters.AddWithValue("#40DRY", _40DRY)
mysqlcommand.Parameters.AddWithValue("#40HDRY", _40HDRY)
mysqlcommand.Parameters.AddWithValue("#40HREF_NOR", _40HREF_NOR)
mysqlcommand.Parameters.AddWithValue("#kayit_eden", kayit_eden)
mysqlcommand.ExecuteNonQuery()
mysqlcommand.Parameters.Clear()
Next
If mysql_connection.State = ConnectionState.Open Then mysql_connection.Close()
End If
End If
ASPxGridView1.DataBind()

How to change row color in datagridview by comparing two columns from different tables using vb.net?

No success!
If user of tblcon with billmonth of tbltrns exists in tbltrns then highlight the rows of tblcon with red color
Code:
Private Sub checkexist()
For Each row As DataGridViewRow In DataGridView1.Rows
ConObj = New SqlConnection(ConStr)
ConObj.Open()
Dim qry As String = "SELECT * FROM tblTrns WHERE userName=#userName and bill_month=#bill_month"
CmdObj = New SqlCommand(qry, ConObj)
CmdObj.Parameters.AddWithValue("#bill_month", DateTimePicker1.Text)
CmdObj.Parameters.AddWithValue("#userName", (row.Cells("User").Value.ToString))
drObj = CmdObj.ExecuteReader()
If drObj.HasRows Then
row.DefaultCellStyle.BackColor = Color.Red
End If
Next
ConObj.Close()
End Sub
Query for the Grid
Public Function GetData() As DataView
ConObj = New SqlConnection(ConStr)
ConObj.Open()
CmdObj = New SqlCommand
dsObj = New DataSet
daObj = New SqlDataAdapter()
Dim SelectQry = "SELECT UserName[User],doj[Connection Date],packagename[Package],profilename[Profile],billing[Payment],fees[Fees],connectionstatus[Status] from TblCon"
CmdObj.CommandText = SelectQry
CmdObj.Connection = ConObj
daObj.SelectCommand = CmdObj
daObj.Fill(dsObj)
TvObj = dsObj.Tables(0).DefaultView
Return TvObj
ConObj.Close()
End Function
Query Changed in getdata but no success. Please guide ...........................................................................................................................................................................................................................................
Public Function GetData() As DataView
ConObj = New SqlConnection(ConStr)
ConObj.Open()
CmdObj = New SqlCommand
dsObj = New DataSet
daObj = New SqlDataAdapter()
Dim SelectQry = Dim SelectQry = "SELECT UserName[User],doj[Connection Date],packagename[Package],profilename[Profile],billing[Payment],fees[Fees],conn‌​‌​‌​ectionstatus[Status], (SELECT ISNULL(COUNT(*), 0) FROM tblTrns WHERE tblTrns.userName = tblCon.UserName AND bill_month = '" & DateTimePicker1.Text & "') [Comparison] from TblCon"
CmdObj.CommandText = SelectQry
CmdObj.Connection = ConObj
daObj.SelectCommand = CmdObj
daObj.Fill(dsObj)
TvObj = dsObj.Tables(0).DefaultView
Return TvObj
ConObj.Close()
End Function
I recommend you to fill a new column in your grid with a value for comparison and set it's visibility to false.
You can do that by a subselect or a left join on the second table (if you wish an example just post the query that fills your grid).
Based on your comparison column you can use the CellPainting event of the GridView. Like this:
Private Sub grdGridView_CellPainting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles grdGridView.CellPainting
If e.RowIndex >= 0 Then
If grdGridView.Rows(e.RowIndex).Cells("colComparison").Value <> "0" And Not IsNothing(grdGridView.Rows(e.RowIndex).Cells("colComparison").Value) Then
e.CellStyle.BackColor = Color.OrangeRed
e.CellStyle.SelectionBackColor = Color.IndianRed
End If
End If
End Sub

parameter causes the data unreadable in the form 2 does not appear on the web version of vb.net

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim id As String, sLogon_User As String, sAuth_User As String, sUser_ID As String
Dim sServer_Name As String
Dim sIP_Address As String
sIP_Address = Request.ServerVariables("REMOTE_ADDR")
Dim hit As New PagePosting
Dim currentPosting As Posting = CmsHttpContext.Current.Posting
Dim webContext As WebAuthorContext
webContext = WebAuthorContext.Current
'sNama_Perusahaan = Request.QueryString("sentraID")
'Response.Write("masuk sini dgn nilai = " & CmsHttpContext.Current.CmsQueryString())
sData = ""
If Not Page.IsPostBack Then
'sNama_Perusahaan = Request.ServerVariables("sentraID")
sNama_Perusahaan = Request.QueryString("sentraID")
' sNama_Perusahaan = Request.QueryString("sentraID")
Response.Write("masuk sini dgn nilai = " & Request.QueryString("sentraID") & sNama_Perusahaan)
tampil(sNama_Perusahaan)
End If
Sub tampil(ByVal sParam As String)
Dim rd As SqlDataReader
Dim myConnection = New SqlConnection(ConfigurationSettings.AppSettings("RegBIK"))
myConnection.Open()
Dim adadata As Integer
' Dim myCommand As New SqlCommand("select count (*) from kuesioner where ltrim(rtrim(NmPerush)) ='aaa'", myConnection)
Dim myCommand As New SqlCommand("select count (*) from kuesioner where ltrim(rtrim(NmPerush)) ='&sParam'", myConnection)
rd = myCommand.ExecuteReader
While rd.Read
adadata = rd.GetInt32(0)
End While
myConnection.close()
Try
If adadata > 0 Then
myConnection.Open()
' Dim myCommands As New SqlCommand("select * from kuesioner where ltrim(rtrim(NmPerush)) ='aaa'", myConnection)
Dim myCommands As New SqlCommand("select * from kuesioner where ltrim(rtrim(NmPerush)) ='&sParam'", myConnection)
rd = myCommands.ExecuteReader
While rd.Read
disabledAll()
Me.btnUpload.Enabled = False
Me.btnPreview.Enabled = True
txtNmPerush.Value = rd.GetString(1)
Me.txtNmPemilik.Value = rd.GetString(2)
Me.txtAlmtPerush.Value = rd.GetString(3)
Me.txttlpn.Value = rd.GetString(4)
Me.txtEmail.Value = rd.GetString(5)
Me.txtLamaPerush.Value = rd.GetString(6)
Me.txtJenis.Value = rd.GetString(7)
Me.txtSpesialisasi.Value = rd.GetString(8)
Me.txtkualitas.Value = rd.GetString(9)
Me.txtMerk.Value = rd.GetString(10)
Me.txtStandarPesanan.Value = rd.GetString(11)
Me.txtProduksi.Value = rd.GetString(12)
Me.txtlokal.Value = rd.GetString(13)
Me.txtnasional.Value = rd.GetString(14)
Me.txtekspor.Value = rd.GetString(15)
Me.txtpengalaman.Value = rd.GetString(16)
Me.txtlamaekspor.Value = rd.GetString(17)
Me.txtbiaya.Value = rd.GetString(18)
End While
Else
clearAll()
End If
rd.Close()
myConnection.close()
Catch SQLexc As SqlException
Response.Write("Open Failed. Error Details are: " & SQLexc.ToString())
End Try
End Sub
the source code to get the first parameter, the second to throw codingan parameters to form 2 and the third codingan to read in the form 2..I've tried but still can not
I would think that that code would produce an error, but you did not state that.
To add a parameter to the SQL statement:
Dim myCommand As New SqlCommand("SELECT COUNT(*) FROM kuesioner WHERE LTRIM(RTRIM(NmPerush)) = #param1", myConnection)
myCommand.Parameters.Add(New SqlParameter With {.ParameterName = "param1", _
.SqlDbType = SqlDbType.NVarChar, _
.Size = 200, _
.Value = sParam})
Please alter the .SqlDbType and .Size to match the definition in the database.

getting error while updating record in VB.Net

in my form, when i modify data i'm getting error as
'Command text was not set for the command object'
I'm using oledb connection
Following us my code
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
sql = "select * from Employee"
conn = New OleDbConnection(s)
adapt = New OleDbDataAdapter(sql, conn)
ds = New DataSet
usql = "Update Employee set enp_name=?, emp_addr=?, DOB=?, DOJ=?, emp_mob=?, emp_mail=? where ID=?"
ucmd = New OleDbCommand(isql, conn)
Dim date1 As Date
date1 = DateTimePicker1.Value
p = ucmd.Parameters.Add("#emp_name", OleDbType.Char)
p.SourceColumn = "emp_name"
p.SourceVersion = DataRowVersion.Current
p = ucmd.Parameters.Add("#emp_addr", OleDbType.Char)
p.SourceColumn = "emp_addr"
p.SourceVersion = DataRowVersion.Current
p = ucmd.Parameters.Add("#DOB", OleDbType.DBDate)
p.SourceColumn = "DOB"
p.SourceVersion = DataRowVersion.Current
p = ucmd.Parameters.Add("#DOJ", OleDbType.DBDate)
p.SourceColumn = "DOJ"
p.SourceVersion = DataRowVersion.Current
p = ucmd.Parameters.Add("#emp_mob", OleDbType.Integer)
p.SourceColumn = "emp_mob"
p.SourceVersion = DataRowVersion.Current
p = ucmd.Parameters.Add("#emp_mail", OleDbType.Char)
p.SourceColumn = "emp_mail"
p.SourceVersion = DataRowVersion.Current
p = ucmd.Parameters.Add("#ID", OleDbType.Integer)
p.SourceColumn = "ID"
p.SourceVersion = DataRowVersion.Current
adapt.UpdateCommand = ucmd
conn.Open()
If conn.State = ConnectionState.Open Then
adapt.MissingSchemaAction = MissingSchemaAction.AddWithKey
adapt.Fill(ds, "ABC")
'conn.Close()
End If
tables = ds.Tables
table = tables("ABC")
rows = table.Rows
cols = table.Columns
row = rows.Find(TextBox1.Text)
row.BeginEdit()
row("ID") = TextBox1.Text
row("emp_name") = TextBox2.Text
row("emp_addr") = TextBox3.Text
row("DOB") = DateTimePicker1.Text
row("DOJ") = DateTimePicker2.Text
row("emp_mob") = TextBox4.Text
row("emp_mail") = TextBox5.Text
row.EndEdit()
'conn.Open()
adapt.Update(ds, "ABC")** Getting error on this line
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
End Sub
But i'm not getting where i'm going wrong.... please help me
You are not setting usql to the ucmd anywhere.
ucmd.CommandText = usql;
Or rather, in your constuctor:
ucmd = New OleDbCommand(isql, conn)
isql should probably be usql. I am guessing there is an isql string field in the class if you are not getting compilation errors.

VB.NET DataSet Update

Why my set of codes didn't update in DataSet? Then it goes to Error. Please anyone check this code and point me out where I am missing. Thanks in advance!
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
Dim conxMain As New SqlConnection("Data Source=SERVER;Initial Catalog=DBTest;Persist Security Info=True;User ID=username;Password=pwds")
Dim dadPurchaseInfo As New SqlDataAdapter
Dim dsPurchaseInfo As New DataSet1
Try
Dim dRow As DataRow
conxMain.Open()
Dim cmdSelectCommand As SqlCommand = New SqlCommand("SELECT * FROM Stock", conxMain)
cmdSelectCommand.CommandTimeout = 30
dadPurchaseInfo.SelectCommand = cmdSelectCommand
Dim builder As SqlCommandBuilder = New SqlCommandBuilder(dadPurchaseInfo)
dadPurchaseInfo.Fill(dsPurchaseInfo, "Stock")
For Each dRow In dsPurchaseInfo.Tables("Stock").Rows
If CInt(dRow.Item("StockID").ToString()) = 2 Then
dRow.Item("StockCode") = "Re-Fashion[G]"
End If
Next
dadPurchaseInfo.Update(dsPurchaseInfo, "Stock")
Catch ex As Exception
MsgBox("Error : ")
Finally
If dadPurchaseInfo IsNot Nothing Then
dadPurchaseInfo.Dispose()
End If
If dsPurchaseInfo IsNot Nothing Then
dsPurchaseInfo.Dispose()
End If
If conxMain IsNot Nothing Then
conxMain.Close()
conxMain.Dispose()
End If
End Try
End Sub
Does your condition in the loop get executed (set a break point!)? Where is the error thrown? What error?
Also, why does it use ToString at all? This seems redundant.
If CInt(dRow.Item("StockID")) = 2 Then
Should be enough.
Finally, you’re performing redundant cleanup:
If conxMain IsNot Nothing Then
conxMain.Close()
conxMain.Dispose()
End If
Dispose implies Close – no need to perform both operations:
Close and Dispose are functionally equivalent.
[Source: MSDN]
Does your dataAdapter has update command ?
(it looks like it doesn't - so it doesn't know what do to with update....)
Here is an Update Command example:(for an employee table with 3 columns - as listed below:
UPDATE [Employee]
SET [name] = #name
, [manager] = #manager
WHERE (([id] = #Original_id) AND
((#IsNull_name = 1 AND [name] IS NULL) OR
([name] = #Original_name)) AND
((#IsNull_manager = 1 AND [manager] IS NULL) OR
([manager] = #Original_manager)));
SELECT id
, name
, manager
FROM Employee
WHERE (id = #id)
You can see it is a general update that can handle changes in any field.
I got it from the error correction of my program by Konard Rudolph!
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
Dim conxMain As New SqlConnection("Data Source=SERVER;Initial Catalog=DBTest;Persist Security Info=True;User ID=username;Password=pwds")
Dim dadPurchaseInfo As New SqlDataAdapter
Dim dsPurchaseInfo As New DataSet1
Try
Dim dRow As DataRow
conxMain.Open()
dadPurchaseInfo.SelectCommand = New SqlCommand("SELECT * FROM Stock", conxMain)
Dim builder As SqlCommandBuilder = New SqlCommandBuilder(dadPurchaseInfo)
dadPurchaseInfo.Fill(dsPurchaseInfo, "Stock")
For Each dRow In dsPurchaseInfo.Tables("Stock").Rows
If CInt(dRow.Item("StockID")) = 2 Then
dRow.Item("StockCode") = "Re-Fashion(H)"
End If
Next
dadPurchaseInfo.Update(dsPurchaseInfo, "Stock")
Catch ex As Exception
MsgBox("Error : " & vbCrLf & ex.Message)
Finally
If dadPurchaseInfo IsNot Nothing Then
dadPurchaseInfo.Dispose()
End If
If dsPurchaseInfo IsNot Nothing Then
dsPurchaseInfo.Dispose()
End If
If conxMain IsNot Nothing Then
conxMain.Dispose()
End If
End Try
End Sub
The above set of code work to update with DataSet! Thanks to stackoverflow community and who answered my question.
Here is ref:
How To Update a SQL Server Database by Using the SqlDataAdapter Object in Visual Basic .NET
How to update a database from a DataSet object by using Visual Basic .NET
p.s: Like o.k.w said : The Table must have primary key. Thanks o.k.w!
--MENU--
Dim login As New LoginClass
login.ShowDialog()
--CONEXION--
Private conec As SqlConnection
Dim stringCon As String = "Data Source= ;Initial Catalog=;Persist Security Info=True;User ID=;Password="
Public ReadOnly Property prConec() As Object
Get
Return conec
End Get
End Property
Public Sub Conectar()
Try
conec = New SqlConnection(stringCon)
If conec.State <> ConnectionState.Open Then
conec.Open()
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
--BUSCAR--
funciones.Conectar()
Dim coman As New SqlCommand("sp_cliente", funciones.prConec)
Dim dt As New DataTable
coman.CommandType = CommandType.StoredProcedure
coman.Parameters.Add("#i_operacion", SqlDbType.Char, 1, ParameterDirection.Input).Value = "B"
dt.Load(coman.ExecuteReader())
grdClientes.DataSource = dt
--INSERTAR--
funciones.Conectar()
Dim coman As New SqlCommand("sp_articulo", funciones.prConec)
coman.CommandType = CommandType.StoredProcedure
coman.Parameters.Add("#i_operacion", SqlDbType.Char, 1, ParameterDirection.Input).Value = "I"
coman.ExecuteNonQuery()
Buscar()
Limpiar()
--COMBO--
Dim dt As New DataTable
dt.Columns.Add("Codigo")
dt.Columns.Add("Descripcion")
Dim dr1 As DataRow = dt.NewRow
dr1.Item("Codigo") = "A"
dr1.Item("Descripcion") = "Activo"
dt.Rows.Add(dr1)
Dim dr2 As DataRow = dt.NewRow
dr2.Item("Codigo") = "I"
dr2.Item("Descripcion") = "Inactivo"
dt.Rows.Add(dr2)
cmbEstado.DataSource = dt
cmbEstado.ValueMember = "Codigo"
cmbEstado.DisplayMember = "Descripcion"
--GRIDVIEW--
--1--
Dim grdFila As DataGridViewRow = grdClientes.CurrentRow
txtCedula.Text = grdFila.Cells(0).Value
--2--
If DataGridProductos.CurrentCell.ColumnIndex = 0 Then
Dim FLstArticulos As New FLstArticulos
FLstArticulos.ShowDialog()
DataGridProductos.CurrentRow.Cells(0).Value = FLstArticulos.PrIdArticulo
End If
--GRIDVIEW.CELLENDEDIT--
If DataGridProductos.CurrentCell.ColumnIndex = 3 Then
Dim precio As New Double
Dim cantidad As New Double
precio = CDbl(grdRow.Cells(2).Value)
cantidad = CDbl(grdRow.Cells(3).Value)
DataGridProductos.CurrentRow.Cells(4).Value = PLTotalFilaItem(cantidad, precio)
PLCargaTotales()
End If
Sub PLCargaTotales()
Dim subTotal As Double
Dim iva As Double
For Each grd As DataGridViewRow In DataGridProductos.Rows
If Not String.IsNullOrEmpty(grd.Cells(4).Value) Then
subTotal = subTotal + CDbl(grd.Cells(4).Value)
End If
Next grd
txtSubtotal.Text = subTotal.ToString
iva = Decimal.Round(subTotal`enter code here` * 0.12)
txtIva.Text = iva.ToString
txtTotalPagar.Text = (subTotal + iva).ToString
End Sub