DataSource Controls :: Sql Lock While Inserting Rows?
Jun 10, 2010What kind of lock will be used on table if there is insert statement made by specifiying value in the insert statement?
View 2 RepliesWhat kind of lock will be used on table if there is insert statement made by specifiying value in the insert statement?
View 2 Repliesi develop a c# windows application. My database is sql server 2008 exp. i want lock single row for user select it for update. for example;
userA - Connection a (connection id 52);
user select a single row (select * from t1 with(rowlock?, updlock?,or what) where id=1) and bind data to form fields (texbox, checkbox,combobox etc.). (there is no problem)
userB - Connection b (connection id 54);
userB can select all other rows from t1 (where id=2 or 3 or anything) but not id=1. when userB select * from t1 where id=1 system generate an exception with (you cannot select this row because it is updated. Updated users connection id is 52.)
when userA (connectionid52) close form or commit changes then userB can select id=1.
i am read few documents (transacions, rowlock,updlock, concurrency violation optimistic,pessimistic) but i couldn't understand.
I am currently trying to create a web from that takes multiple lines and inserts them in to multiple rows in sql. So basically On the Web form It will have the following info
Store No = "28" Activity = "Bake Cake" Date = "3/3/11"
Store No = "28" Activity = "Eat Cake" Date = "3/6/11"
Store No = "28" Activity = "Sell Lemonade" Date = "2/3/11"
Store No = "28" Activity = "Bake Fudge" Date = "3/30/11"
Store No = "28" Activity = "Eat Cookies" Date = "5/3/11"
Currently I am using this script to insert values into SQL:
[Code]....
I am having trouble inserting rows from a DetailsView. I am using a profiler, and I can see that 18 parameters are being passed in to my procedure where there should only be 10.
Here is the markup, and it is followed by the query that is sent to my database:
[Code]....
My problem is this "I have all the tools, VS 2005, 2008, 2010. I have every book, I have SQL server 2005 and 2008" I have all the tools, but I do not know what tool or technology to use when starting out learning all this. I juat do not know what book teaches what I need to do for something like below.
Here is my question:
I created an .ASPX webform that is to "Submit" to a SQL 2005 database. I gave this form to my DBA, and he has made up a Data Model. Now I have to figure out how to write the ASP.NET code so it will submit to the DB. My first issue is not knowing this:
1. "How do I loop through my CheckBox List", and then insert the values checked into a "Database Table" (Each Checkbox value MUST be a seperate row in the table, the DBA does not want a seperate column for each checkbox value)
2. The database is using stored procedures
3. My third issue is this: "I do not know "where" to put the "code". If you do resond to this,
Summary: I just need shown the code on how to "loop through" the CheckBox List on my form, and insert those values into a database table as seperate rows.
I have one big DataTable with X rows. I want to select Y rows from it and bind them to a new ViewList. While doing it, I want to delete these rows from the DataTable (Having X - Y rows).
What is the best and fast way to do it?
I don't know if it is better to create a new DataTable to have the Y and after that bind them to a ViewList or something else?
I'm also looking for example in code how to select/delete rows from DataTable.
[Code]....
In above query I want to have top 10 rows as well as count of all rows.
code for inserting rows by button click on table or grid
View 5 RepliesThis is the first time I have been working on databases and I am trying to insert data using an object datasource but no data is being inserted and no exception is thrown. I'm not sure where I am going to wrong. I am putting user data into session variables and inserting the session variables into the dataacess class layer and have a try and exception but nothing being thrown. Any help would be really appreciated because I don't know even where to start looking with this or how I can get the error to be thrown. Please see some of my code below to give an idea of what I am doing
Object Access Class
public void InsertCarPolicyHolder(PolicyHolderClass ph, CarInsuranceOptions options)
{
[code]...
I'm linking a form to sql database, As far as i know for textbox the code will be like this one below in VB:
dashDataSource.InsertParameters.Add("databaseColumName", NameOFTextBox.Text)
But what is the code for a drop down menu for countries list?
I have a formview that is working fine for with the exception of the username is not inserting on a new record. The username is visible on login so I know that is working. I'm attaching my sql code as well as the code behind as I don't know what I'm missing.
[Code]....
The topic of sql server deadlock has been discussed many times, however, I was unsure that even two simultaneous inserts on a table can end up in a deadlock situation. Scenario: While testing our application (SQL Server 2005 as backend, ASP.net 3.5) we inserted records into a table simultaneously (simplified overview) and that resulted into a deadlock for more than 70% of users.
I could not get a hang of this as how an insert is being deadlock as this is not a case of multiple resources. After a detailed analysis (of reproducing the bug by two users) I found that both the processes were holding a RangeS-S lock on the primary key index of the table and were trying to convert this into RangeI-N lock, that resulted into a deadlock and one transaction being killed.
Question: Can we avoid or reduce these kind of deadlocks as this is not a case of change in order of access of resources? Cant' we force the transaction to get exclusive lock initially so that it blocks the other process and avoid deadlock? What (adverse) effects that may have? Also could some one explain more about RangeI-N lock.
Isolation Level for this was "Serializable".
When I m trying with my code to insert a name like "Cédric" the field in the Database is empty.Here is my code for the insert function :
[Code]....
Here is the code that call this function :
[Code]....
I need to insert a Boolean value into an SQL Server datatable. I'm having a problem with what I'm trying. I don't see the option for a Boolean data type in SQL Server so I used Binary(1). Is this the right data type for storing Boolean in SQL Server?
The lines:
cmd.Parameters.Add(New SqlParameter("@Active", SqlDbType.Binary, 1))
cmd.Parameters("@Active").Value = False
generate the following error on the execute command:
InvalidCastException: Invalid cast from 'System.Boolean' to 'System.Byte[]'
Is there an example somewhere that covers how to store a boolean in an SQL Server table?
What is the best method in T-SQL 2008 for extending a table's records with the criteria of 'repeating' all fields but the Primary KEY e.g. Consecutive Date for the previous n Records.
So you have for example 7 records (Easy...2 Fields. Date and nvarchar) with th Date runing from Jan-01 to Jan-07
We want to extend the table by 21 records...so
Record 1,8,15,22 will look identical apart from the DateField.
Record 2,9,16,23 will look identical apart from the DateField. etc...etc..
I have tried a number of methods ...all coming up short....
I am building an app (ASP.NET 3.5 + SQL 2005) that allow users to schedule meetings and these meeting will show in the users to-do list.
One kind of meeting, when scheduled, should show into ALL users to-do list.
I have 3 tables:
#1 - Users -> UserID
#2 - Meetings -> MeetingID
#3 - Member_Meeting -> UserID+MeetingID
What I need is:
Based on the scheduled meeting, read all users from table #1 and add their info in the table # 3 with the MeetingID (which I can get from the UI, because it will happen when they create the meeting).
I have been browsing about it, but so far, I couldn't find a good source of info to start with.
Im trying to get the ID out of the record that i'm inserting using scope_identity. I've add the following line of code to the Insert statements in the sqldatasource - SET @insID = Scope_Identity() I've add the following line to the Insert parameter list
asp:Parameter
Name="insID"
Type="Int32"
Direction="Output"
I now want to insert a number records into the database using the following:
Dim insID As Object = e.Command.Parameters("@insID").Value ' gets out latest ID
Dim ordernumber As String = "CX" & insID.ToString & DateTime.Now.DayOfYear.ToString
sqlOrders.InsertParameters("orderNumber").DefaultValue = ordernumber
sqlOrders.InsertParameters("orderDate").DefaultValue = DateTime.Now
sqlOrders.InsertParameters("customerID").DefaultValue = userID
sqlOrders.InsertParameters("productID").DefaultValue = productID
sqlOrders.InsertParameters("totalPrice").DefaultValue = "0.00"
sqlOrders.InsertParameters("status").DefaultValue = "Paid"
I currently have this code in the SQLDataSource_Inserting sub but the first line only works once the record is inserted. How can i get the ID out as im inserting the parameters?
I have a table with casenum as primary number and Identity column turned on. I know that the casenum will only auto-generated after a record is written into a table.
The front end to this table is a FormView on an AJAX webform.
Table is linked to the webform via LinqDataSource.
Now, on the webform, how can I display nextval before the record is actually written into a table?
I have two tables cust and order_cust cust table have cust_id, name, addr, zip columns and order_cust have order_id and cust_id columns I take input from user for cust table i.e. name, addr, zip... the cust_id is an IDENTITY column so generates the value automatically Now I want to insert the last generated cust_id into order_cust (order_id is also an IDENTITY column)
How can I achieve that using stored procedure?
I have an editable grid where user can add/edit data. They also have the option to load previously entered data from last month. When the user then clicks save, i want to readd this newly modified data as a new record for this month. So basically I want to call the insertcommand, but it does not work. My 'save' method just 'updates' the records.
Providing sqldatasource, grid and save method
<asp:SqlDataSource ID="SqlDataSourceLoadActivities" runat="server" [code].....
I have the logged-in user's Guid stored in a session variable. My understanding is that when the Guid is passed to the session variable it becomes a string. When I use the detailsview control I have to convert the session variable back to a guid and I've been doing it like this and it seems to work fine:
e.values("UserId") = session("LoggedInUserId")
Dim UserId as Guid = New Guid()
When I try to use the Insert() command after the following:
SqlDataSource3.InsertParameters("UserId").DefaultValue = Session("LoggedInUserId")
I get an "InvalidCastException" error with the comment "Conversion from type 'Guid' to type 'String' is not valid." I'm assuming the session variable needs to be converted to a type Guid since that's what I've had to do with the Detailsview control. I've tried a few different ways of converting the session variable back to a Guid so the insert command will work, but no matter which method of conversion I try I get errors such as "value of type system.guid cannot be converted to 'string'. I'm confused because I thought I was supposed to convert it from a string to a Guid. The "UserId" parameter is a non-primary key uniqueidentifier in the database.
I have a table right now with just customer_id and customer_name and I want to add an image field to upload their logo.
I've searched and found articles on how to create a table and to upload an image for a new row but how do I update or add a picture to an existing row.
So if I browse through my table and found a customer without a logo or an outdated logo, how do I replace and update their logo?
I want to insert data in my tblOrder with surent paramater
I get the controls out of al my paramaters.
But ons of my controls contains the text of a Title of a book.
In my table i want to to insert this book_id. The title of this book is in an other table tblBoek. But i want to enter al my data in tblOrders.
TblOrders Tbloek
ID ID
Naam Titel
Boek_ID Auteur
the Boek_ID is i an relationship with the ID form tblBoek
SQL:"INSERT INTO tblOrders (ID, NAME, ADDRESS, DATE, BOOK_ID,) " +
"WHERE
"VALUES (@Id, @Name, @Address, @Date, )"; //for my parameters these values are in controls
"FROM tblOrders INNER JOIN tblBooks ON tblOrders.BOOK_ID = tblBooks.BOOK_ID";
SOMETHING WITH WHERE
but the books ID doesnt work without it it will
Whenever I run the following code to insert a record into database:
protected void Button1_Click(object sender, EventArgs e)
Inserting Related Entities?
View 14 Replies