DBNull value for parameter is not supported. Table-valued parameters cannot be DBNull - sql

I am currently trying to pass a two table value parameters from a .net application to a database.
The error that I am getting is
DBNull value for parameter '#StageNotes' is not supported. Table-valued parameters cannot be DBNull.
I have checked that the parameter value is not null when I pass it, and the error that I get is not a sqlException, rather just a general Exception that passes this error back
The parameters are declared like so
Dim stageNotesparamTable2SQL As New SqlParameter("#StageNotes", SqlDbType.Structured)
Dim responsesParamTable2SQL As New SqlParameter("#Responses", SqlDbType.Structured)
and the values are assigned like this
Dim responseTable = ResponsesToDt()
responsesParamTable2SQL.Value = responseTable
Dim stageTable = StageNotesToDt()
stageNotesparamTable2SQL.Value = stageTable
The parameters are declared in the stored proc like this
#StageNotes [App].[StageNotesTableType] READONLY,
#Responses [app].QuestionResponseTableType READONLY,
When debugging I see that the stageNotesparamTable2SQL.Value is showing that there is a datatable in there and has the data so it is definitely not null.
I would be grateful if anyone could help me with this.
thanks
-- edit ---
Protected Function ResponsesToDt() As DataTable
Dim dt As New DataTable()
dt.Columns.Add("CheckId", GetType(Integer))
dt.Columns.Add("QuestionId", GetType(Integer))
dt.Columns.Add("AnswerId", GetType(Integer))
dt.Columns.Add("StaffNumber", GetType(String)).MaxLength = 15
Dim dictValues = _dicOfControlsAndValues.Where(Function(x) x.Key.Contains("ddl_Stage_"))
For Each item In dictValues
Dim ddlIdBreakDown = item.Key.ToString().Split("_").ToList
Dim checkid As Integer = item.Key.ToString().Split("_").Last
Dim questionId As Integer = Convert.ToInt16(ddlIdBreakDown(4))
Dim answerId As Integer = Convert.ToInt16(item.Value)
Dim staffNumber As String = GetLoggedOnStaffNumber()
dt.Rows.Add(checkid, questionId, answerId, staffNumber)
Next
Return dt
End Function
Protected Function StageNotesToDt() As DataTable
Dim dt As New DataTable
dt.Columns.Add("CheckId", GetType(Integer))
dt.Columns.Add("StageId", GetType(Integer))
dt.Columns.Add("StageNotes", GetType(String))
dt.Columns.Add("ModifiedDate", GetType(String))
Dim dictValues = _dicOfControlsAndValues.Where(Function(x) x.Key.Contains("textArea_Stage"))
For Each item In dictValues
Dim stageNote As String = String.Empty
Dim ddlIdBreakDown = item.Key.ToString().Split("_").ToList
If String.IsNullOrEmpty(item.Value.ToString()) Then
stageNote = "."
Else
stageNote = item.Value.ToString()
End If
Dim checkid As Integer = item.Key.ToString().Split("_").Last
Dim stageId As Integer = Convert.ToInt16(ddlIdBreakDown(2))
Dim stageNotes As String = stageNote
Dim modifiedDate As DateTime = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")
dt.Rows.Add(checkid, stageId, stageNotes, modifiedDate)
Next
Return dt
End Function
-- edit 2 --
DAL.ExecCommand("[App].[usp_SaveCheckDetails]", "",
checkIdParam,
userIdParam,
caseNoteParam,
checkNoteParam,
checkCompletedParam,
CheckFeedbackSentToUserId,
stageNotesparamTable2SQL,
responsesParamTable2SQL)
Then the DAL im having to call.
The DAL is a shared repo that Im not able to edit at the moment:
Public Function ExecCommand(ByVal spName As String, ByVal connStringName As String, ByVal ParamArray SPParms() As SqlClient.SqlParameter) As Boolean
Dim SqlConnection As New SqlConnection
Dim sqlCommand As New SqlClient.SqlCommand
Dim returnCode As Boolean = False
Try
If connStringName <> "" Then
SqlConnection.ConnectionString = ConfigurationManager.ConnectionStrings(connStringName).ConnectionString
Else
SqlConnection.ConnectionString = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
End If
sqlCommand.CommandType = CommandType.StoredProcedure
sqlCommand.CommandText = spName
For Each p As SqlParameter In SPParms
If p.Direction <> ParameterDirection.Output Then
If Not p.Value.GetType() = GetType(Integer) Then
If p.Value.ToString() = "" OrElse p.Value = Nothing Then
p.Value = DBNull.Value
End If
End If
End If
sqlCommand.Parameters.Add(p)
Next
sqlCommand.Connection = SqlConnection
SqlConnection.Open()
sqlCommand.ExecuteNonQuery()
returnCode = True
Catch sqlEx As SqlException
HelpersErrorHandling.WriteAppLogEntry(Me.GetType().Name, System.Reflection.MethodBase.GetCurrentMethod().ToString, sqlEx)
Catch ex As Exception
If Not ex.Message.ToString().Contains("Thread was being aborted") Then
HelpersErrorHandling.WriteAppLogEntry(Me.GetType().Name, System.Reflection.MethodBase.GetCurrentMethod().ToString, ex)
End If
Finally
Try
sqlCommand.Parameters.Clear()
sqlCommand.Dispose()
SqlConnection.Close()
SqlConnection.Dispose()
Catch ex As Exception
HelpersErrorHandling.WriteAppLogEntry(Me.GetType().Name, System.Reflection.MethodBase.GetCurrentMethod().ToString, ex)
End Try
End Try
Return returnCode
End Function

Related

Read the Response and stored to database using Microsoft SMO (Server Management Objects)

Im trying to call to an URL
And than i will get response into XML format and based what Response i will get it will create Tables successfully into database using Microsoft SMO (Server Management Objects) which Allowing me to create and generate databases and tables. but for some reason it coludnt insert any data to tables and they are NULL Screenshot
XML:
<ICECAT-interface xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://data.icecat.biz/xsd/files.index.xsd">
<files.index Generated="20200219011050">
<file path="export/freexml.int/EN/1424.xml" Product_ID="1424" Updated="20200218012414" Quality="ICECAT" Supplier_id="1" Prod_ID="C4811A" Catid="846" On_Market="1" Model_Name="11" Product_View="513730" HighPic="http://images.icecat.biz/img/gallery/1424_6912543175.jpg" HighPicSize="2478427" HighPicWidth="2598" HighPicHeight="3276" Date_Added="20051023000000" Limited="No" >
<M_Prod_ID Supplier_id="11" Supplier_name="Cisco">C4811A</M_Prod_ID>
<M_Prod_ID>Tempcomp3109</M_Prod_ID>
<Country_Markets>
<Country_Market Value="NL"/>
<Country_Market Value="BE"/>
<Country_Market Value="FR"/>
<Country_Market Value="UA"/>
<Country_Market Value="GB"/>
<Country_Market Value="DE"/>
<Country_Market Value="BG"/>
</Country_Markets>
</file>
</files.index>
</ICECAT-interface>
Module:
Class Module1
Public Shared Sub Main()
Dim url As String = "http://data.Icecat.biz/export/freexml/EN/daily.index.xml"
ProcessXMLFeedURL(url)
End Sub
Public Shared Function ProcessXMLFeedURL(MyURL As String) As Boolean
Dim OK As Boolean = False
Try
Dim rssReq As WebRequest = WebRequest.Create(MyURL)
Dim username As String = ""
Dim password As String = ""
Dim encoded As String = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(username + ":" + password))
rssReq.Headers.Add("Authorization", "Basic " + encoded)
'//Get the WebResponse
Dim rep As WebResponse = rssReq.GetResponse()
'//Read the Response in a XMLTextReader
Dim xtr As XmlTextReader = New XmlTextReader(rep.GetResponseStream())
'// Set up the connection to the SQL server
Dim MyConnectionString As String = "Data Source=......"
Dim Connection As SqlConnection = New SqlConnection(MyConnectionString)
Dim MyServer As Server = New Server(New ServerConnection(Connection))
Dim db As Database = New Database(MyServer, "xxxxx")
db.Create()
'//Create a new DataSet
Dim ds As DataSet = New DataSet()
'//Read the Response into the DataSet
ds.ReadXml(xtr)
'// Parse tables
For i As Integer = 0 To ds.Tables.Count - 1
Dim Mytable As Table
Dim MyTableName As String = ds.Tables(i).TableName
If Not HaveTable(MyConnectionString, MyTableName) Then
'// Create the table
Try
Mytable = New Table(db, MyTableName)
Catch ex As Exception
Dim ii As Integer = 0
End Try
'// Create the columns
Dim Mycolumn As Column = New Column()
For Each dc As DataColumn In ds.Tables(i).Columns
Mycolumn = New Column(Mytable, dc.ColumnName)
Mycolumn.DataType = getdatatype(dc.DataType.ToString)
Mytable.Columns.Add(Mycolumn)
Next
Mytable.Create()
Dim PrimaryKeys() As DataColumn = ds.Tables(i).PrimaryKey
Dim PrimaryKey As DataColumn
For Each PrimaryKey In PrimaryKeys
Dim Myindex As Index = New Index(Mytable, PrimaryKey.ColumnName)
Myindex.IndexKeyType = IndexKeyType.DriPrimaryKey
Myindex.IndexedColumns.Add(New IndexedColumn(Myindex, PrimaryKey.ColumnName))
Mytable.Indexes.Add(Myindex)
Next
End If
Using MyConnection As SqlConnection = New SqlConnection(MyConnectionString)
MyConnection.Open()
Using bulkcopy As SqlBulkCopy = New SqlBulkCopy(MyConnection)
bulkcopy.DestinationTableName = "[" & MyTableName & "]"
Try
bulkcopy.WriteToServer(ds.Tables(i))
Catch ex As Exception
Dim iw As Integer = 0
End Try
End Using
MyConnection.Close()
End Using
Next
Catch ex As Exception
Throw ex '// Do errorhanddling here
End Try
Return OK
End Function
Shared Function getdatatype(Mydatatype As String) As DataType
Dim dty As DataType = Nothing
Select Case Mydatatype
Case Is = "System.Decimal"
dty = DataType.Decimal(2, 18)
Case Is = "System.String"
dty = DataType.VarChar(500)
Case Is = "System.Int32"
dty = DataType.Int
End Select
Return dty
End Function
Shared Function HaveTable(MyConnectionString As String, TableName As String) As Boolean
Dim OK As Boolean = False
Try
Dim dbConn As New SqlConnection(MyConnectionString)
dbConn.Open()
Dim restrictions(3) As String
restrictions(2) = TableName
Dim dbTbl As DataTable = dbConn.GetSchema("Tables", restrictions)
If dbTbl.Rows.Count > 0 Then
OK = True
End If
dbTbl.Dispose()
dbConn.Close()
dbConn.Dispose()
Catch ex As Exception
Dim ss As Integer = 0
End Try
Return OK
End Function
End Class
Can anyone please help me!

Oracle.ManagedDataAccess Procedures with Date as a Parameter causing exception

create or replace PROCEDURE PROCEDURE_ONE(
T1_CURSOR OUT SYS_REFCURSOR,
Date_Start_P in Date Default sysdate
)
as
begin
OPEN T1_CURSOR FOR ...
This works when testing with Oracle SQL Developer
My VB.Net code doesn't like the parameter
Private Function Load_Aging_Stock() As DataTable
Try
Dim dba As New Data_Access_Class
Dim strSQL As String = "JOHN.PROCEDURE_ONE"
Dim dt As DataTable
Dim cmd As OracleCommand = dba.CreateStoredProcCommand(strSQL)
Dim oracleParameter(1) As OracleParameter
oracleParameter(0) = New OracleParameter()
oracleParameter(1) = New OracleParameter()
cmd.BindByName = True
With cmd
oracleParameter(0) = cmd.Parameters.Add("T1_Cursor", dbType:=Oracle.ManagedDataAccess.Client.OracleDbType.RefCursor, ParameterDirection.Output)
'.Parameters.Add("T1_CURSOR", OracleClient.OracleType.Cursor).Direction = ParameterDirection.Output
If Me.chk_No_Date_Start.Checked = False Then
Dim tmpDate As String = CDate(Me.dt_Start_Date.Text.Trim).ToString("yyyy-MM-dd")
oracleParameter(1) = cmd.Parameters.Add("Date_Start_P", dbType:=Oracle.ManagedDataAccess.Client.OracleDbType.Varchar2, val:=tmpDate, ParameterDirection.Input)
'.Parameters.Add("Date_Start_P", OracleClient.OracleType.DateTime).Value = Me.dt_Start_Date.Text
End If
End With
dt = dba.ExecuteSelectCmdDataTbl(cmd)
Return dt
Catch ex As Exception
Dim Err As New SS_Errors("frm__Report", "Load_Report", ex)
Return Nothing
End Try
End Function
I've also tried the same code but replaced Varchar2 with Date and both times, I get the same exception
One of the identified items was in an invalid format.
Don't pass the string as parameter value, just use the Date value, i.e.
oracleParameter(1) = cmd.Parameters.Add("Date_Start_P", dbType:=OracleDbType.Date, val:=CDate(Me.dt_Start_Date.Text.Trim), ParameterDirection.Input)

VB.Net freezing when adding 10000+ rows to SQL from list

I am running a RESTful API service which gets data from a server as a JSON string. Around 20000 rows are being selected.
Dim js As New JavaScriptSerializer()
Dim prodlist As List(Of Product) = js.Deserialize(Of List(Of Product))(JSONreturn)
The 20000 rows are populated in the list prodlist. Checked the count and manually verified the list.
I need to insert these rows in a client machine. However, while inserting the rows, it freezes or stops after inserting around 600-700 rows. Below is the code I am using for inserting.
For Each item As Product In prodlist
Dim SPName As String = "someSPname"
With connectionstring
.Clear()
.Parameters("#itemnumber", SqlDbType.VarChar, ParameterDirection.Input, , item.itemnumber
.Parameters("#itemtype", SqlDbType.VarChar, ParameterDirection.Input, , item.itemtype)
.Parameters("#DESCRIPTION", SqlDbType.VarChar, ParameterDirection.Input, , item.DESCRIPTION)
.Execute(SPName)
End With
Next
No error is thrown. It just freezes after inserting roughly 600-700 rows everytime.
Bulk insert is not an option. How do I resolve this?
UPDATE : Adding connection class. Pretty sure there is no issue with this :
Public Class ConnectionClass
Public ReadOnly Property ConnectionString() As String
Get
Return GetConfiguration()
End Get
End Property
Public Sub Parameters(ByVal param_name As String, ByVal type As SqlDbType, ByVal direction As ParameterDirection, Optional param_size As Int32 = Nothing, Optional param_value As Object = Nothing)
Dim sqlParam As SqlParameter = Nothing
Try
sqlParam = New SqlParameter(param_name, type)
sqlParam.Size = param_size
sqlParam.Direction = direction
sqlParam.Value = param_value
Lstparam.Add(sqlParam)
Finally
If sqlParam IsNot Nothing Then
sqlParam = Nothing
End If
End Try
End Sub
Public Sub Execute(ByVal strSpName As String, Optional ByVal Type As CommandType = CommandType.StoredProcedure)
Try
sqlcmd = New SqlCommand()
sqlcmd.Connection = connection
''Setting the timeout to 50 mins as setup in the previous application
sqlcmd.CommandTimeout = 3000
If transaction IsNot Nothing Then
sqlcmd.Transaction = transaction
End If
sqlcmd.CommandType = Type
sqlcmd.CommandText = strSpName
For Each argument As SqlParameter In Lstparam
sqlcmd.Parameters.Add(argument)
Next
For introw As Integer = 0 To sqlcmd.Parameters.Count - 1
If sqlcmd.Parameters.Item(introw).ParameterName.Contains("Parameter") Then
sqlcmd.Parameters.Item(introw).ParameterName = String.Empty
End If
Next
sqlcmd.ExecuteNonQuery()
Catch ex As Exception
Throw
End Try
End Sub
Public Sub Clear()
ClearParameters()
Lstparam.Clear()
End Sub
Public Sub ClearParameters()
If Not sqlcmd Is Nothing Then
Do Until sqlcmd.Parameters.Count = 0
sqlcmd.Parameters.Clear()
Loop
End If
End Sub
Public Function GetConfiguration() As String
Dim sbConnectionString As New StringBuilder
With sbConnectionString
.Append("Data Source=")
.Append(ServerName)
.Append(";")
.Append("Initial Catalog =")
.Append(DatabaseName)
.Append(";")
.Append("User ID =")
.Append(UserName)
.Append(";")
.Append("Password =")
.Append(UserPassword)
End With
Return sbConnectionString.ToString()
End Function
Public Function CreateClientConnection() As SqlConnection
Dim connectionString As String
Try
connectionString = GetConfiguration()
Dim substrings() As String = connectionString.ToUpper.Split(";")
Dim substrings1() As String = connection.ConnectionString.ToUpper.Split(";")
If Not (connection.State = ConnectionState.Open) Then
connection.ConnectionString = connectionString
connection.Open()
ElseIf Not (Trim(substrings(0)) = Trim(substrings1(0))) Then
If connection IsNot Nothing Then
connection.Dispose()
End If
connection.ConnectionString = connectionString
connection.Open()
End If
Return connection
Catch ex As Exception
If connection IsNot Nothing Then
connection.Dispose()
End If
Throw ex
End Try
End Function
End Class

oracle bulkcopy from vb.net databale

I am loading the CSV file to vb.net datatable .
then I am using Bulk copy command to write to database.
The problem is if one date cell in the data table is empty, i am receiving
ORA:-01840 input value not long enough for date format.
How to resolve this.
Public Class Form1
Dim cn As New OracleConnection("Data Source =(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = ipaddressofserver)(PORT = portofserver))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = oracleservicename)) ) ; User Id=useridofdb;Password=passwordofdb")
cn.Open()
MsgBox("connection opened")
Dim dt As DataTable = ReadCSV("D:\test.csv")
DataGridView1.DataSource = dt
Try
Dim _bulkCopy As New OracleBulkCopy(cn)
_bulkCopy.DestinationTableName = "TEST_TABLE"
_bulkCopy.BulkCopyTimeout = 10800
_bulkCopy.WriteToServer(dt)
cn.Close()
cn.Dispose()
cn = Nothing
MsgBox("Finished")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Function ReadCSV(ByVal path As String) As System.Data.DataTable
Try
Dim sr As New StreamReader(path)
Dim fullFileStr As String = sr.ReadToEnd()
sr.Close()
sr.Dispose()
Dim lines As String() = fullFileStr.Split(ControlChars.Lf)
Dim recs As New DataTable()
Dim sArr As String() = lines(0).Split(","c)
For Each s As String In sArr
recs.Columns.Add(New DataColumn())
Next
Dim row As DataRow
Dim finalLine As String = ""
For Each line As String In lines
row = recs.NewRow()
finalLine = line.Replace(Convert.ToString(ControlChars.Cr), "")
row.ItemArray = finalLine.Split(","c)
recs.Rows.Add(row)
Next
Return recs
Catch ex As Exception
Throw ex
End Try
End Function
End Class

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