sqlparameter

Getting timeout errors with SqlTransaction on same table

删除回忆录丶 提交于 2019-12-11 18:03:10
问题 public TransImport() { ConnString = ConfigurationManager.ConnectionStrings["Connection"].ConnectionString; SqlConnection conn_new; SqlCommand command_serial_new; SqlConnection conn; SqlCommand command_serial; SqlTransaction InsertUpdateSerialNumbers; conn = new SqlConnection(ConnString); command_serial = conn.CreateCommand(); conn_new = new SqlConnection(ConnString); command_serial_new = conn_new.CreateCommand(); command_serial_new.CommandText = "SELECT 1 FROM YSL00 WHERE SERLNMBR = @slnr";

InsertCommand.Parameters.Add size parameter for datetime

百般思念 提交于 2019-12-11 00:46:10
问题 I need to know what the size parameter should be for a DateTime value using the following syntax: adapter.InsertCommand.Parameters.Add("@deliveryDateAndTime", SqlDbType.DateTime,10,"deliveryDateAndTime"); I cannot use the following syntax because I'm batching the updates in a datatable. adapter.InsertCommand.Parameters.Add("@deliveryDateAndTime", SqlDbType.DateTime); adapter.InsertCommand.Parameters["@deliveryDateAndTime"] = *variable*.value; Below is the code I need to use (abbreviated for

How to call Stored Procedures (with 2 parameters) in a Stored Procedure?

[亡魂溺海] 提交于 2019-12-06 20:04:26
问题 I have stored procedures with same parameters (server name and date). I want to write a stored procedure and Exec them in that SP (called it SP_All). CREATE PROCEDURE [dbo].[SP_All] AS BEGIN exec sp_1 @myDate datetime, @ServerName sysname exec sp_2 @myDate datetime, @ServerName sysname exec sp_3 @myDate datetime, @ServerName sysname exec sp_4 @myDate datetime, @ServerName sysname END Go error: Must declare the scalar variable "@myDate". 回答1: I see two issues here: Your procedure apparently

How to use SQL parameters to get dataset from SQL Server

浪尽此生 提交于 2019-12-05 02:03:40
问题 I'm working on C# project and I'm new to this technology. I want to read some data from SQL Server 2008, and I write the following code public User select(string username, string password) { string connection = ConfigurationManager.ConnectionStrings["lawyersDBConnectionString"].ConnectionString.ToString(); string sql = string.Format("select * from users where userName = '{0}' and password = '{1}'", username, password); SqlConnection con = new SqlConnection(); con.ConnectionString = connection

SqlParameter with default value set to 0 doesn't work as expected

你。 提交于 2019-12-04 08:53:03
问题 I was doing something like this: SqlParameter param = new SqlParameter("@Param", 0) { SqlDbType = SqlDbType.Int }; private void TestParam(SqlParameter param) { string test = param.Value.ToString(); // Getting NullReferenceException here } But I stop getting the exception when I put it like this: SqlParameter param = new SqlParameter("@Param", SqlDbType.Int) { Value = 0 }; private void TestParam(SqlParameter param) { string test = param.Value.ToString(); // Everything OK } Can anyone tell me

Return value from OleDbCommand

北城余情 提交于 2019-12-04 06:58:37
sqlQuery = "SELECT [ID] from [users] WHERE CallerName=@CallerName"; OleDbConnection conn = new OleDbConnection(connectionString); conn.Open(); cmd = new OleDbCommand(sqlQuery, conn); cmd.CommandText = sqlQuery; cmd.Parameters.Add("@CallerName", OleDbType.VarChar).Value = labelProblemDate.Text.Trim(); cmd.Parameters["@CallerName"].Value = name; cmd.ExecuteNonQuery(); conn.Close(); I was told that this is how to read data from a SELECT query using Parameters but it's not working. I think I did something wrong. I am using WinForms and Microsoft Access 2007 It looks like you have your answer, but

Can't solve “Sqlparameter is already contained by another SqlparameterCollection”

跟風遠走 提交于 2019-12-04 06:09:40
问题 I am using 2 threads (from same class) in a windows service. I always getting the same error message: "The SqlParameter is already contained by another SqlParameterCollection. at System.Data.SqlClient.SqlParameterCollection.Validate(Int32 index, Object value) at System.Data.SqlClient.SqlParameterCollection.Add(Object value) at System.Data.SqlClient.SqlParameterCollection.Add(SqlParameter value) at DataBaseLayer.SqlDataBaseLayer.FillDataSetFromProcedure(String strStoredProc, ArrayList

how to pass sql parameter as null value in integer datatype variable?

让人想犯罪 __ 提交于 2019-12-04 03:16:17
how to pass sql parameter as null value in to integer data type variable ? StockBO sBO = new StockBO(); sBO.Mode = 2; if (ddcmpanyname.SelectedIndex != 0) { sBO.Client_id = Convert.ToInt16(ddcmpanyname.SelectedValue); } else { sBO.Client_id = Convert.ToInt16(DBNull.Value);//Object cannot be cast from DBNull to other types. sBO.Client_id =DBNull.Value;//Cannot implicitly convert type } ds=_StockController.StockGet(sBO); i changed the code like this it gives error like i my comment check else part Try this, else { sBO.Client_id = System.Data.SqlTypes.SqlInt32.Null; } It's not entirely clear what

SqlParameter with default value set to 0 doesn't work as expected

一曲冷凌霜 提交于 2019-12-03 02:17:44
I was doing something like this: SqlParameter param = new SqlParameter("@Param", 0) { SqlDbType = SqlDbType.Int }; private void TestParam(SqlParameter param) { string test = param.Value.ToString(); // Getting NullReferenceException here } But I stop getting the exception when I put it like this: SqlParameter param = new SqlParameter("@Param", SqlDbType.Int) { Value = 0 }; private void TestParam(SqlParameter param) { string test = param.Value.ToString(); // Everything OK } Can anyone tell me why SqlParameter assumes 0 is the same as null? Edit: MSDN Explains this here: SqlParameter Constructor

Difference between DbNull.Value and DbNull.Value.ToString()

孤街醉人 提交于 2019-12-02 07:25:48
问题 I wanted to learn which usage is true? if(!string.IsNullOrEmpty(parentID)) cmd.Parameters.Add(new SqlParameter("@ParentSesID", parentID)); else cmd.Parameters.Add(new SqlParameter("@ParentSesID", DBNull.Value)); OR if(!string.IsNullOrEmpty(parentID)) cmd.Parameters.Add(new SqlParameter("@ParentSesID", parentID)); else cmd.Parameters.Add(new SqlParameter("@ParentSesID", DBNull.Value.ToString())); 回答1: cmd.Parameters.Add(new SqlParameter("@ParentSesID", parentID)); This is passing a parentID to