-
慕勒3428872
三个步骤:第一步:声明数据库连接对象: Sqlconnection connection=new Sqlconnection(ConnectionString);第二步:声明数据库操作对象: 两种途径:直接以字符串拼接的方式形成sql语句,比如:sqlstr="insert into usertab(uid,pwd) values('"+uidtxt+"','"+pwdtxt+"')";SqlCommand command = new SqlCommand(sqlstr, connection);以参数占位的先行成形式语句,然后对参数实行绑定,比如: sqlstr="insert into usertab(uid,pwd) values(@uidtxt,@pwdtxt)"; SqlCommand command = new SqlCommand(sqlstr, connection); command.Parameters.Add("@uidtxt", SqlDbType.Text); command.Parameters["@uidtxt"].Value =uidtxt; command.Parameters.Add("@pwdtxt", SqlDbType.Text); command.Parameters["@pwdtxt"].Value =uidtxt;执行数据库操作: command.ExecuteNonQuery(); connection.close();
-
慕的地10843
可以使用xml当参数之后 在用存储过程接收,例如DECLARE @idoc intDECLARE @doc nvarchar(max)SET @doc ='<roots> <root> <id>1</id> <name>a</name> </root> <root> <id>2</id> <name>b</name> </root></roots>'EXEC sp_xml_preparedocument @idoc OUTPUT, @docSELECT*FROM OPENXML (@idoc, '/roots/root',2)WITH (id nvarchar(10),name nvarchar(100))insert into ....
-
隔江千里
添加引用Oracle.DataAccess.dll using Oracle.DataAccess.Client;123456789OracleBulkCopy sqlBulk = new OracleBulkCopy("User ID=root;Password=***;Data Source=xx.x.x.x;", OracleBulkCopyOptions.UseInternalTransaction); sqlBulk.DestinationTableName = "表名"; foreach(DataColumn column in dtTable.Columns) { sqlBulk.ColumnMappings.Add(column.ColumnName,column.ColumnName); } sqlBulk.WriteToServer(dtTable); sqlBulk.Dispose(); sqlBulk.Close();