查看: 1293|回复: 9
|
请问关于VB.NET/mysql的两个小问题-keep datagrid update
[复制链接]
|
|
在VB.NET用datetimepicker选了特定的一天
要把它update存进mysql里
请问要怎么写?
现在只可以用Now()
myCommand.CommandText = "INSERT INTO trydt(DTrecord, Date, Time)" _
& "VALUES(NOW(), ?Date, NOW())"
myCommand.Parameters.Add("?Date", DateTimePicker1.Text)
我用以上这段有问题
在database里面有一个table
里面有一项是Time datatype是time
可是在VB.NET用datagrid show table的时候
只是出00:00:00
这是原因?
[ Last edited by shohoku on 14-6-2005 at 04:01 PM ] |
|
|
|
|
|
|
|
发表于 9-6-2005 09:09 AM
|
显示全部楼层
你的 datagrid 显示资料是怎么写的呢? |
|
|
|
|
|
|
|
楼主 |
发表于 9-6-2005 11:25 AM
|
显示全部楼层
Dim myCommand As New OdbcCommand
Dim myData As New DataTable
Dim SQL As String
Dim myAdapter As New OdbcDataAdapter
Dim conn As OdbcConnection
conn = New OdbcConnection
conn.ConnectionString ="DRIVER={MySQL ODBC 3.51 Driver};" & _
"SERVER=localhost;" & _
"DATABASE=seas;" & _
"UID=root;" & _
"PASSWORD=;" & _
"OPTION=3;"
SQL = "SELECT * from trydt"
conn.Open()
myCommand.Connection = conn
myCommand.CommandText = SQL
myAdapter.SelectCommand = myCommand
myAdapter.Fill(myData)
Me.DataGrid1.DataSource = myData
除了Now()还有什么方法是记单单时间的
如果要save用datetimepicker和Monthcalendar进database的话
要怎么写??
谢谢~~~ |
|
|
|
|
|
|
|
发表于 9-6-2005 10:11 PM
|
显示全部楼层
INSERT INTO table1 ( ID, Description, DateTime)
VALUES ( '123', 'test', '2005-06-23 23:59:00' );
UPDATE table1 SET Description='test2', DateTime = '2005-06-23 22:11:03' WHERE `ID` =123; |
|
|
|
|
|
|
|
发表于 9-6-2005 10:13 PM
|
显示全部楼层
CREATE TABLE table1(
ID bigint( 20 ) NOT NULL AUTO_INCREMENT ,
Description text,
DateTime datetime NOT NULL default '0000-00-00 00:00:00',
PRIMARY KEY ( ID )
) |
|
|
|
|
|
|
|
楼主 |
发表于 10-6-2005 03:02 AM
|
显示全部楼层
Dim conn As New OdbcConnection
Dim myCommand As New OdbcCommand
conn = New OdbcConnection
conn.ConnectionString= "DRIVER={MySQL ODBC 3.51 Driver};" & _
"SERVER=localhost;" & _
"DATABASE=seas;" & _
"UID=root;" & _
"PASSWORD=;" & _
"OPTION=3;"
myCommand.Connection = conn
myCommand.CommandText = "INSERT INTO tryinsert(Name)" _
& "VALUES(@Name)"
myCommand.Parameters.Add("@Name", TextBox1.Text)
conn.Open()
myCommand.ExecuteNonQuery()
conn.Close()
请问上面这part有什么错呢?
到ExecuteNonQuery就会出error... |
|
|
|
|
|
|
|
发表于 10-6-2005 08:54 AM
|
显示全部楼层
Error Message 是什么呢? |
|
|
|
|
|
|
|
发表于 11-6-2005 02:35 PM
|
显示全部楼层
shohoku 于 10-6-2005 03:02 AM 说 :
Dim conn As New OdbcConnection
Dim myCommand As New OdbcCommand
conn = New OdbcConnection
conn.ConnectionString= "DRIVER={MySQL ODBC 3.51 Driver};" & _
&q ...
myCommand.CommandText = "INSERT INTO tryinsert(Name)" _
& "VALUES(@Name)"
应该是
myCommand.CommandText = "INSERT INTO tryinsert(Name)" & _
"VALUES(@Name)"
可是很奇怪,这个应该不会导致ExecuteNonQuery error |
|
|
|
|
|
|
|
楼主 |
发表于 14-6-2005 03:18 PM
|
显示全部楼层
又有问题请教一下
我的data show在datagrid
如果我想要保持它每30秒update一次
能做得到吗?
要怎么写? |
|
|
|
|
|
|
|
楼主 |
发表于 14-6-2005 03:21 PM
|
显示全部楼层
add data的问题暂时解决了
之前的不懂什么问题
换另一种写法了
如果说要edit data
那edit之后要存了database里面
是不是用.update? |
|
|
|
|
|
|
| |
本周最热论坛帖子
|