vb.net添加数据库 vbnet操作数据库

怎样用VB.NET实现对数据库的添加Insert Into 数据表名 (字段1,字段2,...) Values ('字段1值','字段2值'....)
VB.NET怎样连接数据库Imports System.Data
Imports System.Data.SqlClient
Module 连接数据库
Public Server1 As String
Public DataBase1 As String
Public Function GetTable(ByVal sqlstr$) As DataTable
Dim SqlConn As SqlConnection = New SqlConnection("server="Server1";database="DataBase1";integrated security=true")'声明这些SQL的类
Dim facDataAdapter As SqlDataAdapter = New SqlDataAdapter
Dim SqlComm As SqlCommand = New SqlCommand(sqlstr, SqlConn)
facDataAdapter.SelectCommand = SqlComm
Dim dt As DataTable = New DataTable
facDataAdapter.Fill(dt)
Return dt
End Function
End Module
vb.net 写数据库你这是向sql后台数据库写数据吗?
sqldataadapter1.update 改须指定有效的updatecommand,我一直没有看到
给你个例子你看吧:
'首先指定有效的UpdateCommand
sqlstr = "insert into Playlist(PlayName,PlayPath)values('"TextBox4.Text.Trim"','"TextBox5.Text.Trim"')"
Module1.Mycommand.CommandText = sqlstr
'增加新一行(此行必须,要不不能与后台同步,并且后面调用update会出错)
Module1.MyDataSet.Tables("Music").Rows.Add()
Module1.MyDataAdaPter.InsertCommand = Module1.Mycommand
Module1.MyDataAdaPter.Update(Module1.MyDataSet, "Music")
MsgBox("增加数据成功?。?)
VB.NET DATAGRIDVIEW写入数据库【vb.net添加数据库 vbnet操作数据库】Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim sqlStr As String = "insert into tb values("
Dim i As Integer
For i = 0 To DataGridView1.Columns.Count - 1
sqlStr = "'"DataGridView1.Rows(DataGridView1.Rows.Count - 1).Cells(i)"'"
If iDataGridView1.Columns.Count - 1 Then sqlStr = ","
Next
sqlStr = ")"
Dim con As New SqlConnection(connectionString) '这个自己写去
con.Open()
Dim cmd As New SqlCommand(sqlStr, con)
Try
Dim result As Integer = cmd.ExecuteNonQuery()
If result0 Then
MsgBox "添加数据成功"
Else
MsgBox "添加数据失败"
End If
Catch (ex As Exception)
MsgBox "添加数据过程发生异常,原因:"ex.Message
End Try
End Sub
VB.NET将datagridview的数据插入数据库Dim strConn As String = "driver={microsoft access driver (*.mdb)};uid=admin;pwd=;dbq="
Application.StartupPath"\ACCESS.MDB"
Dim cn As New OdbcConnection(strConn)
cn.Open()
Dim da As New OdbcDataAdapter("Select * From 表名", cn)
Dim ds As New DataSet
da.Fill(ds, "表名")
Dim cmdBuilder As New OdbcCommandBuilder(da)
da.InsertCommand = cmdBuilder.GetInsertCommand
With ds.Tables("表名")
For i = 0 to DataGridView1.Rows.Count - 1
Dim dr As DataRow = .NewRow
dr("列名1") = DataGridView1中的值
.
.
.
dr("列名n") = DataGridView1中的值
.Rows.Add(dr)
next
End With
da.Update(ds.Tables("表名"))
cn.Close()
vb.net 如何读出excel,并把数据插入oracle数据库中 。用FORMULA
1
,一个开源框架;里面有个JBook可以取到EXCEL中的数据;然后你在根据JBook将数据存到数据库
答案补充
导入的时候打开一个JFileChooser用来让用户选择要读的excel文件;然后JBook
WorkBook
=
new
JBook();WorkBook.read(fileName,
new
ReadParams(JBook.eFileExcel97));WorkBook.setSheet(0);WorkBook.setSelection(0,
0,
0,
0);这就将excel中的数据读入JBook中了,int
EndRow
=
WorkBook.getLastRow();//
总行数int
EndCol
=
WorkBook.getLastCol();//
总列数WorkBook.getNumber(row,col);
或者getText(row,col)活的excel中的数据;将这些数据从JBOOK提取出来,然后自己封装成自己需要的类型,再存到数据库就行了;说起来好像挺繁琐的 , 做做试试;去网上下个FORMULA
1
的jar包我现在是在java的CS模式下用的;
关于vb.net添加数据库和vbnet操作数据库的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

    推荐阅读