string sql="indes ioto teble(id,name) valuse ('"+a+"','"+b+"')";C#里这样的语句 其中A和B可以是变量吗?最好能写个小例子
解决方案 »
- jquery滑动门问题
- 关于WEB项目的后台管理的问题!!
- 如何设置HyperLinkField打开的网页不含地址栏和设定固定大小?
- 如何实现在点击asp:button按钮后,不刷新当前页面?
- 关于JS对话框与CSS的问题???
- 小调查,大家是怎么访问数据库的?
- 有关DataGrid itemdatabound事件问题??
- 请大家帮忙解释一下这段代码。谢谢
- 请问使用CDO组件要多少版本的。NET FRAMEK才支持,急急!!!!!
- 简单问题:怎样去掉textbox控件的滚动条!
- 我想把用户的登录信息用全局变量的形式保存下来。请问用什么方法?Session,数据表等?您们是用什么方法呢?
- 再提出个问题,大家帮看看
str_Command = str_Command + " WHERE loginid = '" + strid + "'";
str_Command = str_Command + " AND pwd = '" + strpwd + "'";
Func.ReplaceStr(ProdModel.Text)+"',factory='"+Func.ReplaceStr(factory.Text)+"',madeFrom='"+Func.ReplaceStr(MadeFrom.Text)+
"',costPrice='"+Func.ReplaceStr(CostPrice.Text)+"',MarkPrice='"+Func.ReplaceStr(MarkPrice.Text)+"',MemPrice='"+
Func.ReplaceStr(MemPrice.Text)+"',is_special='"+str_special+"',specialPrice='"+Func.ReplaceStr(specialPrice.Text)+"',specialfull='"+
Func.ReplaceStr(due.Text)+"',InfoClsIndex='"+Func.ReplaceStr(ord.Text)+"',is_index='"+str_index+"',is_comm='"+str_comm+
"',info='"+Func.ReplaceStr(inf.Text)+"',description='"+Func.ReplaceStr(Content.Text)+"'";
string b = TextBox2.Text.Replace("'","''");System.Data.SqlClient.SqlConnection cnn = new System.Data.SqlClient.SqlConnection("连接字符串");
System.Data.SqlClient.SqlCommand cm = new System.Data.SqlClient.SqlCommand();
cm.Connection = cnn;
cm.CommandText = "insert into table1 (id) values('"+a+"','"+b+"')";
cnn.Open();
cm.ExecuteNonQuery();
cnn.Close();
Dim strSql As String = "Select * From company_user Where userID='" & UserID & "' and userPWD='" & UserPWD & "'"
'判断用户名或密码是否正确,并登陆
Dim cmd As New SqlCommand(strSql, conn)
Dim dr As SqlDataReader = cmd.ExecuteReader()
If dr.Read() <> True Then
Response.Write("<script language='javascript'>alert('用户名或密码错误!');</" & "script>")
Else
If dr.GetValue(2) = 1 Then
Session("class") = dr.GetValue(2)
Response.Redirect("index1.html")
Else
Session("class") = dr.GetValue(2)
Response.Redirect("index2.html")
End If
End If
string b = TextBox2.Text; System.Data.SqlClient.SqlConnection cnn = new System.Data.SqlClient.SqlConnection("连接字符串");
System.Data.SqlClient.SqlCommand cm = new System.Data.SqlClient.SqlCommand();
cm.Connection = cnn;
cm.CommandText = "insert into table1 (field1,field2) values(@field1,@field2)";
cm.Parameters.Add("@field1",SqlDbType.VarChar);
cm.Parameters["@field1"].Value = a;
cm.Parameters.Add("@field2",SqlDbType.VarChar);
cm.Parameters["@field2"].Value = b;
cnn.Open();
cm.ExecuteNonQuery();
cnn.Close();
for(int i=1;i++;i<=40)
{
string sql="INSERT INTO table (id,name) valuse ('"+ id+1 +"','"+name+1+"')";
com.ExecuteNonQuery();
}
类似上面的东西 请多帮忙
string[] b = new string[]{name1,name2,name3,...}; System.Data.SqlClient.SqlConnection cnn = new System.Data.SqlClient.SqlConnection("连接字符串");
System.Data.SqlClient.SqlCommand cm = new System.Data.SqlClient.SqlCommand();
cm.Connection = cnn;
cm.CommandText = "insert into table1 (field1,field2) values(@field1,@field2)";
cnn.Open();
for(int i=0;i<a.Length;i++)
{
cm.Parameters.Add("@field1",SqlDbType.VarChar);
cm.Parameters["@field1"].Value = a[i];
cm.Parameters.Add("@field2",SqlDbType.VarChar);
cm.Parameters["@field2"].Value = b[i];
cm.ExecuteNonQuery();
}
cnn.Close();
其中a,b都是变量
//插入操作
System.Data.SqlClient.SqlConnection cnn = new System.Data.SqlClient.SqlConnection("server=.;uid=sa;pwd=;database=数据库名");
System.Data.SqlClient.SqlCommand cm = new System.Data.SqlClient.SqlCommand();
cm.Connection = cnn;
cm.CommandText = sql;
cnn.Open();
cm.ExecuteNonQuery();
cnn.Close();
这样就可以完成了