
当然,可以声明一个模块级变量,当用鼠标单击某一个 datagridview 控件的时候,就把该 datagridview 控件名赋予该模块级变量,然后在删除键的事件里,执行删除前,根据该模块级变量里保存的信息,来确定针对某个 datagridview 控件进行删除 *** 作。
不过还是建议你每一个 datagridview 控件 对应使用一个删除按钮。
public class StudentService
{
//从配置文件中读取数据库连接字符串
private readonly static string connString = ConfigurationManagerConnectionStrings["accpConnectionString"]ToString();
private readonly static string dboOwner = ConfigurationManagerConnectionStrings["DataBaseOwner"]ToString();
AdoNetModelsStudent model = new Student();
// const string spName = "usp_DeleteStudent";
#region 删除数据1
public int DeleteStudent(int stuID)
{
int result = 0;
// 数据库连接 Connection 对象
SqlConnection connection = new SqlConnection(connString);
// 构建删除的sql语句
string sql = stringFormat("Delete From Student Where stuID={0}", stuID);
// 定义command对象
SqlCommand command = new SqlCommand(sql, connection);
try
{
connectionOpen();
result = commandExecuteNonQuery(); // 执行命令
}
catch (Exception ex)
{
ConsoleWriteLine(exMessage);
}
finally
{
connectionClose();
}
return result;
}
#endregion
#region 删除数据2
public int DeleteStudent2(int stuID)
{
int result = 0;
// 构建删除的sql语句使用参数
string sql = "Delete From Student Where stuID=@stuID";
using (SqlConnection connection = new SqlConnection(connString))
{
SqlCommand objCommand = new SqlCommand(sql, connection);
objCommandParametersAdd("@stuID", SqlDbTypeInt)Value = stuID;
connectionOpen();
result = objCommandExecuteNonQuery();
}
return result;
}
#endregion
public int InsertStudent(Student model)
{
int result = 0;
SqlConnection connection = new SqlConnection(connString);
// 构建插入的sql语句
string sql = stringFormat("INSERT INTO Student (stuName,age) values('{0}','{1}')",
modelStuName, modelAge);
// 定义command对象
SqlCommand command = new SqlCommand(sql, connection);
try
{
connectionOpen();
result = commandExecuteNonQuery(); // 执行命令
}
catch (Exception ex)
{
ConsoleWriteLine(exMessage);
}
finally
{
connectionClose();
}
return result;
}
public int InsertStudent2(Student model)
{
int result = 0;
// 构建插入的sql语句
string sql = "INSERT INTO Student (age,stuName) values(@age,@stuName)";
using (SqlConnection connection = new SqlConnection(connString))
{
SqlCommand objCommand = new SqlCommand(sql, connection);
objCommandParametersAdd("@age", SqlDbTypeInt)Value = modelAge;
objCommandParametersAdd("@stuName", SqlDbTypeNVarChar, 50)Value = modelStuName;
connectionOpen();
result = objCommandExecuteNonQuery();
}
return result;
}
public int InsertStudent3(Student model)
{
int result = 0;
using (SqlConnection connection = new SqlConnection(connString))
{
SqlCommand objCommand = new SqlCommand(dboOwner + "usp_InsertStudent", connection);
objCommandCommandType = CommandTypeStoredProcedure;
objCommandParametersAdd("@age", SqlDbTypeInt)Value = modelAge;
objCommandParametersAdd("@stuName", SqlDbTypeNVarChar, 50)Value = modelStuName;
connectionOpen();
result = objCommandExecuteNonQuery();
}
return result;
}
public int InsertStudent5(Student model)
{
int outputResult = 0;
int returnvalue = 0;
using (SqlConnection connection = new SqlConnection(connString))
{
SqlCommand objCommand = new SqlCommand(dboOwner + "usp_InsertStudent", connection);
objCommandCommandType = CommandTypeStoredProcedure;
objCommandParametersAdd("@age", SqlDbTypeInt)Value = modelAge;
objCommandParametersAdd("@stuName", SqlDbTypeNVarChar, 50)Value = modelStuName;
//定义输出参数
SqlParameter parameter = new SqlParameter("@stuID", SqlDbTypeInt);
parameterDirection = ParameterDirectionOutput;
objCommandParametersAdd(parameter);
//定义ReturnValue参数
objCommandParametersAdd("ReturnValue", SqlDbTypeInt);
objCommandParameters["ReturnValue"]Direction = ParameterDirectionReturnValue;
connectionOpen();
objCommandExecuteNonQuery();// 执行命令
//获取输出参数的值在命令执行以后
outputResult = (int)objCommandParameters["@stuID"]Value;
//存储过程中为定义return值默认为0
returnvalue = (int)objCommandParameters["ReturnValue"]Value;
}
return returnvalue;
}
public IList<Student> GetAllStudents1()
{
IList<Student> dataList = new List<Student>();
DataSet dataSet = new DataSet();// 声明并初始化DataSet
SqlDataAdapter dataAdapter; // 声明DataAdapter
using (SqlConnection conn = new SqlConnection(connString))
{
// 定义command对象
SqlCommand command = new SqlCommand(dboOwner + "usp_SelectStudentsAll", conn);
commandCommandType = CommandTypeStoredProcedure;
//Command定义带参数的SQL语句的参数
//commandParametersAdd("@stuID", SqlDbTypeInt);
//给输入参数赋值
//commandParameters["@stuID"]Value = 5;
connOpen();
// 初始化 DataAdapter
dataAdapter = new SqlDataAdapter(command);
// 填充 DataSet
dataAdapterFill(dataSet, "dataSetName");
// 处理数据集中的数据
foreach (DataRow row in dataSetTables[0]Rows)
{
Student model = new Student();
modelStuId = ConvertToInt32(row["stuID"]);
modelStuName = ConvertToString(row["stuName"]);
dataListAdd(model);
}
}
return dataList;
}
public void MoreResult()
{
DataSet dataSet = new DataSet();// 声明并初始化DataSet
SqlDataAdapter dataAdapter; // 声明DataAdapter
// 定义查询语句
string sql = stringFormat("SELECT FROM student where stuid>50;SELECT FROM student ");
SqlConnection connection = new SqlConnection(connString);
try
{
connectionOpen();
// 初始化 DataAdapter
dataAdapter = new SqlDataAdapter(sql, connection);
// 填充 DataSet
dataAdapterFill(dataSet, "dataSetName");
// 处理数据集中的数据
foreach (DataRow row in dataSetTables[0]Rows)
{
//int gradeId = (int)row["GradeID"];
}
}
catch (Exception ex)
{
ConsoleWriteLine(exMessage);
}
finally
{
connectionClose();
}
}
}
}
PowerBuilder的数据窗口可以使用DeleteRow()函数来删除一行数据。例如:dw_1DeleteRow(1)可以删除第一行数据。PowerBuilder的数据窗口可以使用DeleteRow()函数来删除一行数据。例如:dw_1DeleteRow(1)可以删除第一行数据。
如果是CMD窗口:
进入MySQL安装目录/bin下
输入mysql
输入用户名
密码
进入那个表所在的数据库
use
databasename;
drop
table
tablename;
删除SQL Server数据库可直接在MicroSoft SQL Managerment Studio中进行删除。
使用工具:SQL Server 2008 R2 MicroSoft SQL Managerment Studio。
1、使用MicroSoft SQL Managerment Studio登录到指定数据库。
2、点击左侧的“数据库”。
3、然后会出现数据库的列表,右键点击要删除的库名,如要删除上图中的“wxzn”。,则右键点击,会出现“删除”选项。
4、点击“删除”按钮,会有d出窗口,按如图选择,并点击“确定”按钮。
5、执行完毕后,会发现名为“wxzn”的数据库消失了。
以上就是关于vb.net窗口中存在多个datagridview表格,如何删除选中表格的数据及其绑定的数据库中的数据全部的内容,包括:vb.net窗口中存在多个datagridview表格,如何删除选中表格的数据及其绑定的数据库中的数据、visual studio做的窗口应用程序,已经连接数据库,如何删除,updata数据、powerbuilder数据窗口删除一条数据等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)