C#中怎么实现表的增删改查
我做了一个实例,希望可以帮助你,记得采纳哦。
我就截图你看吧
添加代码:
if(messagebox.show("请你核对资料","确认",messagebotuton.okcancel,messageboxicon.asterisk)==dialogresult.cancel)
{
return;
}
else
{
string strcn=@"data source=HY-PC\SQLEXPRESS;initial catalog=cjgl;integrated security=true";
sqlconnection cn=new sqlconnection(strcn);
cn.open();
try
{
string sql="insert into KC values('"+textbox1.text+"','"+textbox2.text+"')";
sqlcommand cmd=new sqlcommand(sql,cn);
if(cmd.executenoquery()>0)
{
messagebox.show("添加成功","提示");
form_load(null,null);
}
else
{
messagebox.show("添加失败","提示");
}
}
finally
{
cn.close();
}
}
其余的更新,修改,都差不多
你设计的界面可以截图给我看不?
http://blog.csdn.net/21aspnet/article/details/1540301
using System.Data.SqlClient;
using System.Collections;
using System.Configuration;
SqlDataAdapter da = null;
SqlCommand cmd = null;
DataSet ds = null;
private static string FConnectionString = "Server=服务;Database=数据库;User ID=登陆名;Password=密码;Trusted_Connection=False";
private string ConnectString = "";
SqlConnection conn = new SqlConnection(FConnectionString );
/// <summary>
/// 执行sql语句,输出受影响行数
/// </summary>
/// <param name="strSql">执行的SQL语句</param>
/// <returns>操作状态</returns>
public int DBRunSql(string strSql)
{
if (strSql == null || strSql == "")
{
MessageBox.Show("SQL语句为空!");
return -1;
}
try
{
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = strSql;
cmd.Connection = conn;
int rowCount = cmd.ExecuteNonQuery();
return rowCount;
}
catch
{
return -1;
}
finally
{
if (conn.State == System.Data.ConnectionState.Open)
{
conn.Close();
}
}
}
/// <summary>
/// 执行无参数sql语句,返回数据集
/// </summary>
/// <param name="strSql"></param>
/// <param name="ds"></param>
/// <returns></returns>
public int DBRunSql(string strSql, ref DataSet ds)
{
if (strSql == null || strSql == "")
{
MessageBox.Show("SQL语句为空!");
return -1;
}
try
{
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = strSql;
cmd.Connection = conn;
da = new SqlDataAdapter();
da.SelectCommand = cmd;
da.Fill(ds);
return 0;
}
catch
{
return -1;
}
finally
{
if (conn.State == System.Data.ConnectionState.Open)
{
conn.Close();
}
}
}
如图我做的最短路径分析 vs2008 C#+AE 请问应该怎么实现呢 或者你有相关的界面、代码不?很感谢,论文着急中。。。。