dim sb as new stringbuilder
dim sqlstring as string = ""
private sub btn_save....
call InitialSqlConnection ' connect database
sb.remove(0,sb.lenght)
sb.append("insert into tbl_Mytable ")
sb.append("(ID,Myname)")
sb.append(" values('" & txt_id.text & "',")
sb.append("'" & combobox1.SelectedValue & "')") ' กรณี ต้องการ save value จาก combobox
' หรือ sb.append("'" & combobox.text & "')")
sqlstring = sb.tostring()
With com
.CommandText = sqlstring
.CommandType = CommandType.Text
.ExecuteNonQuery()
End With
end sub
'showdata
Code (VB.NET)
dim da as sqldataadapter
dim ds as new dataset
dim dt as new datatable
call InitialSqlConnection ' connect database
sb.remove(0,sb.length)
sb.append("select distinct Myname from tbl_Mytable ")
sqlstring = sb.tostring()
da = new sqldataadapter(sqlstring,con)
da.fill(ds,"table1")
dt = ds.table("table1")
with combobox1
.displaymember = "Myname"
.datasource = dt
end with