注册 登录
编程论坛 VB.NET论坛

两个问题请教达人!

ysyswanwx 发布于 2011-07-16 19:29, 633 次点击
程序代码:
Try

                    conn = New System.Data.SqlClient.SqlConnection(connstr)
                    conn.Open()
                    Dim barcode As String = tb.Text.ToString
                    Dim aa As New Data.DataSet
                    Dim sadp As New SqlClient.SqlDataAdapter
                    Dim sqltile As String = "select item_subno as 货号 ,barcode as 条码,item_name as 商品名称 ,unit_no as 单位  ,price as 进价 from bi_t_item_info where barcode='0039'"
                    sadp.SelectCommand = New SqlClient.SqlCommand(sqltile, conn)
                    sadp.Fill(aa)
                    dgd.DataSource = aa.Tables(0)
                    lb1.Items.Add(aa.Tables(0).Rows(0))


                    conn.Close()

                Catch ex As Exception
                    MsgBox("数据库连接错误" & ex.ToString)

                End Try


Dim sqltile As String = "select item_subno as 货号 ,barcode as 条码,item_name as 商品名称 ,unit_no as 单位  ,price as 进价 from bi_t_item_info where barcode='0039'"
此代码处 直接写入一个固定条码 如“0039”,查询成功,但是如果将此改成
Dim sqltile As String = "select item_subno as 货号 ,barcode as 条码,item_name as 商品名称 ,unit_no as 单位  ,price as 进价 from bi_t_item_info where barcode=" & tb.text  (一个文本框)就会报下面的错误
System.Data.SqlClient.SqlException: varchar 值 '013225394694' 的转换溢出了 int 列。超出了最大整数值。
   在 System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
   在 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   在 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
   在 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   在 System.Data.SqlClient.SqlDataReader.HasMoreRows()
   在 System.Data.SqlClient.SqlDataReader.ReadInternal(Boolean setTimeout)
   在 System.Data.SqlClient.SqlDataReader.Read()
   在 System.(SchemaMapping mapping)
   在 System.(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue)
   在 System.(DataSet dataSet, String srcTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords)
   在 System.(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   在 System.(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
   在 System.(DataSet dataSet)
   在 百威数据查询.main.tb_KeyPress(Object sender, KeyPressEventArgs e) 位置 D:\My Documents\Visual Studio 2005\Projects\百威数据查询\百威数据查询\main.vb:行号 61


还有就是怎么样才能把 dataset “aa”中的数据动态添加到listbox中

求相关代码!





[ 本帖最后由 ysyswanwx 于 2011-7-16 19:32 编辑 ]
4 回复
#2
fily13142011-07-29 17:54
当然错误啦,你barcode那里的数据都没有引号
#3
sunzcg8882011-08-07 20:20
barcode='" & tb.text"'  给分吧
#4
ysyswanwx2011-08-10 00:39
楼上说的都不错,问题都已经解决了,谢谢前辈的指导!
#5
wgx3312011-11-05 16:14
谢谢前辈的指导!
1