求助数据库更新问题!!急急!!在线等待

xivi 2003-08-19 10:16:17
Option Explicit On
Option Strict On
Imports System.Data
Imports System.Data.SqlClient

Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows 窗体设计器生成的代码 "

Public Sub New()
MyBase.New()

'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()

'在 InitializeComponent() 调用之后添加任何初始化

End Sub

'窗体重写处置以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer

'注意:以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
Friend WithEvents Label1 As System.Windows.Forms.Label
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.Label1 = New System.Windows.Forms.Label()
Me.SuspendLayout()
'
'Label1
'
Me.Label1.Font = New System.Drawing.Font("宋体", 14.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(134, Byte))
Me.Label1.Location = New System.Drawing.Point(24, 16)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(96, 24)
Me.Label1.TabIndex = 0
Me.Label1.Text = "释放空间"
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 14)
Me.ClientSize = New System.Drawing.Size(136, 61)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Label1})
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)

End Sub

#End Region



Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strcnn As String = "server=jet;database=powerscan;uid=psuser;password=psuser;"

Dim strSQL As String = "select free_space from ps_storage where lmod_user_id='1' and storage_id='1'"
Dim con As New SqlConnection(strcnn)
Dim DS As New DataSet()
Dim DA As SqlDataAdapter
Try
DA = New SqlDataAdapter(strSQL, con)

DA.Fill(DS, "ps_table")
Dim DT As DataTable
Dim DR As DataRow
DT = DS.Tables("ps_table")
DR = DT.NewRow()
Dim myDataRows() As DataRow




myDataRows = DT.Select("storage_id='1'") '问题出现在这句是找不到storage_id这列,但是我在数据库中,又事实上有这个字段。

myDataRows(0).Item("free_space") = "5000" ' 在这句中是说“未将对象引用设置到对象的实例”
'DR.Item("free_space") = "5000"
DA.Update(DS, "ps_table")

Catch er As Exception
MsgBox(er.Message)
End Try

End Sub


End Class


应该如何改???急!!
...全文
39 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
cavok114 2003-10-06
  • 打赏
  • 举报
回复
up
chenzhongfei 2003-10-05
  • 打赏
  • 举报
回复
把这句去掉就行了 DSet.AcceptChanges()
aspsea 2003-09-27
  • 打赏
  • 举报
回复
把 DSet.AcceptChanges() 放在 DAdapter.Update(DSet) 之后看看。

xdangdang 2003-08-20
  • 打赏
  • 举报
回复
嘿嘿
数据库当然被更新
可以通过watch
DataSet的中Datarow的Rowstate看
如果没有更新
看看你是否使用了Transaction
是否Transaction没有提交
dongbeiren 2003-08-19
  • 打赏
  • 举报
回复
你查询中没查出storage_id字段,
Dim strSQL As String = "select * from ps_storage where lmod_user_id='1' and storage_id='1'"
试试
xdangdang 2003-08-19
  • 打赏
  • 举报
回复
Dim strSQL As String = "select free_space from ps_storage where lmod_user_id='1' and storage_id='1'"
这句改成
Dim strSQL As String = "select free_space,storage_id from ps_storage where lmod_user_id='1' and storage_id='1'"
就解决了第一个问题

第二个问题的话
一部分是因为第一个问题引起的
同时最好在这里判一下
if mydataRows.length>0
确定是否有第0行
xivi 2003-08-19
  • 打赏
  • 举报
回复
按照楼上所说,是没有出现错误,但是事实上,数据库中的数据是没有被更新的。只是在DATAGRID中显示出来。
xdangdang 2003-08-19
  • 打赏
  • 举报
回复
出现“未处理的“System.InvalidOperationException”类型的异常出现在 system.data.dll 中

其他信息:更新无法找到 TableMapping[“Table”] 或 DataTable“Table”。
”的错误
是显示DAdapter.Update(DSet)有问题

change
DAdapter.Update(DSet)
to
Dset.tables(0).tablename="table"
Dadapter.update(DSET)
Dset.tables(0).tablename="t1"
greenhill1 2003-08-19
  • 打赏
  • 举报
回复
string sqlSelect="SELECT 学号,姓名,性别,出生年月 FROM 学生 WHERE 年级="+"'"+Form2.toNew1+"'"+"AND 班级="+"'"+Form2.toNew2+"'";

SqlConnection thisConnection=new SqlConnection(@"Data Source=SERVER;User ID=sa;Password=;Initial Catalog=dx");

thisConnection.Open();

SqlDataAdapter thisAdapter=new SqlDataAdapter(sqlSelect,thisConnection);

SqlCommandBuilder thisBuilder=new SqlCommandBuilder(thisAdapter);

thisDataSet=new DataSet();

thisAdapter.Fill(thisDataSet,"学生");

this.thisDataSet.Tables["学生"].Rows[row]["姓名"]=textBox1.Text.Trim();
this.thisDataSet.Tables["学生"].Rows[row]["性别"]=comboBox1.Text.Trim();
this.thisDataSet.Tables["学生"].Rows[row]["出生年月"]=textBox2.Text.Trim();

thisAdapter.Update(this.thisDataSet,"学生");
MessageBox.Show("修改成功!");

dataGrid1.DataSource = thisDataSet.Tables["学生"];

this.thisDataSet_PositionChanged();

thisConnection.Close();
xivi 2003-08-19
  • 打赏
  • 举报
回复
我重新改了一个,但是也是不行啊!!请各位帮我改一改!!!急需!!



Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim strCnn As String = "server=jet;database=powerscan;uid=psuser;password=psuser"
Dim strSQL As String = "select * from ps_storage where storage_id='1'"
Dim Con As New SqlConnection(strCnn)
Dim DAdapter As SqlDataAdapter
Dim DSet As New DataSet()
'Dim DTable As DataTable

DAdapter = New SqlDataAdapter(strSQL, Con)
DAdapter.Fill(DSet, "t1")

'DTable = DSet.Tables("t1")

DataGrid1.DataSource = DSet.Tables(0)

DSet.Tables(0).Rows(0).Item("free_space") = "5000"
DSet.AcceptChanges()

DAdapter.Update(DSet)



End Sub


出现“未处理的“System.InvalidOperationException”类型的异常出现在 system.data.dll 中

其他信息:更新无法找到 TableMapping[“Table”] 或 DataTable“Table”。
”的错误
是显示DAdapter.Update(DSet)有问题
xivi 2003-08-19
  • 打赏
  • 举报
回复
不行啊!!!
求助如何更改了数据库中的数据后,如何更新啊??

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧