ASP.NET提交页面到数据库存储 20
我用的是ASP.NET+ACCESS就是现在页面做好了,如何点提交的时候直接写入ACCESS数据库里?能否小写一段代码处来看看???...
我用的是ASP.NET+ACCESS 就是现在页面做好了,如何点提交的时候直接写入ACCESS数据库里?能否小写一段代码处来看看???
展开
展开全部
/// <summary>
/// 执行增,删除,修改,更新
/// </summary>
/// <param name="Tran_SQL_StoredProcedureName">sql语句或者存储过程名称</param>
/// <param name="Parameters">参数</param>
/// <param name="Parameters_Value">参数值</param>
/// <param name="IsStoreProcedure">是否是存储过程为True这使用存数过程否着反之</param>
/// <returns>返回受影响的行</returns>
public int ExecuteNonQuery(string Tran_SQL_StoredProcedureName, string[] Parameters, object[] Parameters_Value, bool IsStoreProcedure)
{
if (IsStoreProcedure)
{
throw new Exception("该数据库不支持存储过程");
}
else
{
int i = 0;
this.Con = new OleDbConnection(this.ConnectStr);
this.Cmd = new OleDbCommand();
this.Cmd.Connection = this.Con;
this.Cmd.CommandType = System.Data.CommandType.Text;
this.Cmd.CommandText = Tran_SQL_StoredProcedureName;
if (Parameters != null && Parameters_Value != null)
{
AddParametersValue(this.Cmd, Parameters, Parameters_Value);
}
else if (Parameters == null && Parameters_Value != null)
{
AddParametersValue(this.Cmd, Parameters_Value);
}
try
{
if (this.Con.State == System.Data.ConnectionState.Closed)
{
this.Con.Open();
}
i = this.Cmd.ExecuteNonQuery();
Dispose();
}
catch (Exception e)
{
throw new Exception("数据库内部错误", e);
}
finally
{
this.Cmd.Parameters.Clear();
this.Cmd.Dispose();
this.Con.Close();
this.Con.Dispose();
this.Dispose();
}
return i;
}
}
湖北新蓝海是一家专注于网络营销 网络推广的领头企业 ,已为武汉健民、华工激光、江西仁和等多家知名企业提供网络营销外包服务。详情请到各大搜索引擎中搜索“湖北新蓝海”
/// 执行增,删除,修改,更新
/// </summary>
/// <param name="Tran_SQL_StoredProcedureName">sql语句或者存储过程名称</param>
/// <param name="Parameters">参数</param>
/// <param name="Parameters_Value">参数值</param>
/// <param name="IsStoreProcedure">是否是存储过程为True这使用存数过程否着反之</param>
/// <returns>返回受影响的行</returns>
public int ExecuteNonQuery(string Tran_SQL_StoredProcedureName, string[] Parameters, object[] Parameters_Value, bool IsStoreProcedure)
{
if (IsStoreProcedure)
{
throw new Exception("该数据库不支持存储过程");
}
else
{
int i = 0;
this.Con = new OleDbConnection(this.ConnectStr);
this.Cmd = new OleDbCommand();
this.Cmd.Connection = this.Con;
this.Cmd.CommandType = System.Data.CommandType.Text;
this.Cmd.CommandText = Tran_SQL_StoredProcedureName;
if (Parameters != null && Parameters_Value != null)
{
AddParametersValue(this.Cmd, Parameters, Parameters_Value);
}
else if (Parameters == null && Parameters_Value != null)
{
AddParametersValue(this.Cmd, Parameters_Value);
}
try
{
if (this.Con.State == System.Data.ConnectionState.Closed)
{
this.Con.Open();
}
i = this.Cmd.ExecuteNonQuery();
Dispose();
}
catch (Exception e)
{
throw new Exception("数据库内部错误", e);
}
finally
{
this.Cmd.Parameters.Clear();
this.Cmd.Dispose();
this.Con.Close();
this.Con.Dispose();
this.Dispose();
}
return i;
}
}
湖北新蓝海是一家专注于网络营销 网络推广的领头企业 ,已为武汉健民、华工激光、江西仁和等多家知名企业提供网络营销外包服务。详情请到各大搜索引擎中搜索“湖北新蓝海”
展开全部
String strAccConn;
strAccConn = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + "F:\\my dotnets\\DataCon\\DataCon\\gridview.mdb ";
OleDbConnection myOledbConn = new OleDbConnection(strAccConn);
OleDbCommand myOledbCmd = new OleDbCommand();
myOledbCmd.Connection = myOledbConn;
myOledbCmd.CommandText = "insert into Users([ID],[Uname]) values(@tbID,@tbName)";
myOledbCmd.Parameters.AddWithValue("@tbID",tbID.Text);
myOledbCmd.Parameters.AddWithValue("@tbName",tbName.Text);
myOledbConn.Open();
myOledbCmd.ExecuteNonQuery();
myOledbConn.Close();
呵呵 从别的地方抄过来的
strAccConn = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=" + "F:\\my dotnets\\DataCon\\DataCon\\gridview.mdb ";
OleDbConnection myOledbConn = new OleDbConnection(strAccConn);
OleDbCommand myOledbCmd = new OleDbCommand();
myOledbCmd.Connection = myOledbConn;
myOledbCmd.CommandText = "insert into Users([ID],[Uname]) values(@tbID,@tbName)";
myOledbCmd.Parameters.AddWithValue("@tbID",tbID.Text);
myOledbCmd.Parameters.AddWithValue("@tbName",tbName.Text);
myOledbConn.Open();
myOledbCmd.ExecuteNonQuery();
myOledbConn.Close();
呵呵 从别的地方抄过来的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
mission
通用访问类:
public static void connectmission(string sql)
{
using (OleDbConnection conn = new OleDbConnection(System.Configuration.ConfigurationSettings.AppSettings["Tstr"].ToString()))
{
conn.Open();
OleDbCommand cmd = new OleDbCommand(sql, conn);
cmd.ExecuteNonQuery();
}
}
事件:
protected void btnadd_Click(object sender, EventArgs e)
{
string sql = "insert into worklist(workname)values('{0}');
string Tsql = String.Format(sql,txtaddname.Text);
mission.connectmission(Tsql);
}
简单的就是这样~!
通用访问类:
public static void connectmission(string sql)
{
using (OleDbConnection conn = new OleDbConnection(System.Configuration.ConfigurationSettings.AppSettings["Tstr"].ToString()))
{
conn.Open();
OleDbCommand cmd = new OleDbCommand(sql, conn);
cmd.ExecuteNonQuery();
}
}
事件:
protected void btnadd_Click(object sender, EventArgs e)
{
string sql = "insert into worklist(workname)values('{0}');
string Tsql = String.Format(sql,txtaddname.Text);
mission.connectmission(Tsql);
}
简单的就是这样~!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
。。。最好换SQL Server。。。。.net+access。。。记录上千就卡。。。。。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询