vb.net查询SQL结果后小数位太多如何处理
Imports System.Data.SqlClientPublic Class Form1
Dim conn As SqlConnection
Dim da As SqlDataAdapter
Dim ds As DataSet
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
conn = New SqlConnection("server=127.0.0.1;uid=sa;pwd=hx01;database=db_hx")
da = New SqlDataAdapter("SELECT tw_no as 单号,qty as 数量,qty_prc as 存制约量 FROM mf_tw WHERE tw_no LIKE '%" & _
TextBox1.Text & "%'", conn)
ds = New DataSet()
da.Fill(ds, "mf_tw")
DataGridView1.DataSource = ds.Tables("mf_tw")
Catch
MessageBox.Show("语句执行异常!")
End Try
End Sub
End Class
显示结果中数量,在制约量列中显示很多小数位,我使用
SELECT tw_no as 单号,(select rount(qty,2)) as 数量,(select round(qty_prc,2)) as 存制约量 FROM mf_tw WHERE tw_no LIKE '%" & _TextBox1.Text & "%'", conn)
也是不行
QQ:471438206 --------------------编程问答-------------------- 在界面进行格式化,DataGridView1的列可以设置显示格式,或者在cellformatting事件中处理显示格式,数据库中,deciaml格式的好像也能设置小数位数吧 --------------------编程问答-------------------- 设置列显示格式就可以。 --------------------编程问答-------------------- 1L --------------------编程问答--------------------
SELECT tw_no as 单号,cast(qty as decimal(30,2)) as 数量,cast(qty_prc as decimal(30,2)) as 存制约量 FROM mf_tw--------------------编程问答-------------------- 不建议在数据库中设置小位位数,在显示的时候控制格式更加灵活。
补充:.NET技术 , VB.NET