Imports SystemDataSqlClient
Imports SystemDataOleDb
Public Class glyh
Dim conn As New SqlConnection("server=\SQLEXPRESS;database=students;uid=sa;pwd=sa")
Dim da As New SqlDataAdapter()
Dim ds As New DataSet()
Dim str As String
Dim str1 As String
Dim a As Integer
Dim comstr As String
Private Sub glyh_Load(ByVal sender As SystemObject, ByVal e As SystemEventArgs) Handles MyBaseLoad
Try
dsReset()
connOpen()
da = New SqlDataAdapter("select from users", conn)
daFill(ds, "users")
Medgv1DataSource = dsTables("users")
yonghumingDataBindingsAdd(New Binding("text", ds, "users用户名"))
mimaDataBindingsAdd(New Binding("text", ds, "users密码"))
yonghuleixingDataBindingsAdd(New Binding("text", ds, "users用户类型"))
mimatishiwentiDataBindingsAdd(New Binding("text", ds, "users问题"))
mimatishidaanDataBindingsAdd(New Binding("text", ds, "users答案"))
Catch ex As Exception
MessageBoxShow("数据库连接失败" & exToString)
Finally
connClose()
End Try
End Sub
Private Sub dgv1_SelectionChanged(ByVal sender As Object, ByVal e As SystemEventArgs) Handles dgv1SelectionChanged
MeBindingContext(ds, "users")Position = Medgv1CurrentCellRowIndex
End Sub
Private Sub sousuo_Click(ByVal sender As SystemObject, ByVal e As SystemEventArgs) Handles sousuoClick
For i As Integer = 0 To Medgv1RowsCount - 1
If Medgv1Rows(i)Cells(0)ValueEquals(MessyhmText) Then
Medgv1CurrentCell = Medgv1Rows(i)Cells(0)
MeBindingContext(ds, "users")Position = Medgv1CurrentRowIndex
End If
Next
End Sub
End Class
using System;
using SystemCollectionsGeneric;
using SystemComponentModel;
using SystemData;
using SystemDataSqlClient;
using SystemDrawing;
using SystemText;
using SystemWindowsForms;
namespace DataSource
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private DataSet ds = new DataSet();
private SqlConnection conn = null;
private SqlDataAdapter da = null;
private const string DRIVER = "server=;database=northwind;uid=sa;pwd=sa";
private const string sql_select = "select from region";
/
此方法为将数据库northwind中的region表的数据查询出来并放入DataSet中
/
private void Form1_Load(object sender, EventArgs e)
{
conn = new SqlConnection(DRIVER);
da = new SqlDataAdapter(sql_select,conn);
daFill(ds,"table");
thisdataGridView1DataSource = dsTables["table"]DefaultView;
}
private bool BtnInsert() //此方法作用于添加
{
daInsertCommand = connCreateCommand();
daInsertCommandCommandText = "insert into region values(@id,@ption)";
daInsertCommandParametersAdd("@id", SqlDbTypeInt, 4, "regionid");
daInsertCommandParametersAdd("@ption", SqlDbTypeVarChar, 10, "regiondescription");
int count = daUpdate(ds);
bool result = count > 0 true : false;
return result;
}
private void button1_Click(object sender, EventArgs e)
{
if (thisBtnInsert())//调用此方法
{
MessageBoxShow("添加成功!");
}
else
{
MessageBoxShow("添加失败!");
}
}
private bool BtnDelect() //此方法作用于删除
{
SqlParameter sp = new SqlParameter();
daDeleteCommand = connCreateCommand();
daDeleteCommandCommandText = "delete region where regionid=@id";
sp = daDeleteCommandParametersAdd("@id", SqlDbTypeInt, 4, "regionid");
spSourceVersion = DataRowVersionOriginal;
dsTables["table"]Rows[thisdataGridView1CurrentRowIndex]Delete();
int count = daUpdate(ds);
bool result = count > 0 true : false;
return result;
}
private void button2_Click(object sender, EventArgs e)
{
if (thisBtnDelect())//调用删除方法
{
MessageBoxShow("删除成功!");
}
else
{
MessageBoxShow("删除失败!");
}
}
private bool BtnUpdate() //此方法作用于修改
{
SqlParameter sp = new SqlParameter();
daUpdateCommand = connCreateCommand();
daUpdateCommandCommandText = "update region set regionid=@id,regiondescription=@ption where regionid=@oldid";
daUpdateCommandParametersAdd("@id", SqlDbTypeInt, 4, "regionid");
daUpdateCommandParametersAdd("@ption", SqlDbTypeVarChar, 10, "regiondescription");
sp = daUpdateCommandParametersAdd("@oldid", SqlDbTypeInt, 4, "regionid");
spSourceVersion = DataRowVersionOriginal;
int count = daUpdate(ds);
bool result = count > 0 true : false;
return result;
}
private void button3_Click(object sender, EventArgs e)
{
if (thisBtnUpdate())//调用修改方法
{
MessageBoxShow("修改成功!");
}
else
{
MessageBoxShow("修改失败!");
}
}
}
}
以上就是关于VB中单击在 DataGrid1 所显示列表的某一行,如何获得该行第二列的内容 大哥大姐救急啊!!!全部的内容,包括:VB中单击在 DataGrid1 所显示列表的某一行,如何获得该行第二列的内容 大哥大姐救急啊!!!、如何把datagridview控件中一行数据导入SQLSERVER数据库中、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)