If I run it manually on sql server, it fails until the directory column is removed. The type is varchar(50), with a uniqueness constraint. However, this is same type as the title column, which doesn't have this problem.
I have a mixed mode account setup with exec permissions granted on my stored procedures. I am running an sp that is editing a member, and if i run it using my query analyzer with the same login, my sp writes to the db. however, if i'm calling it through my web app (asp.net) it doesn't. here is my sp code:
IF @@ERROR <> 0 BEGIN ROLLBACK TRAN END ELSE COMMIT TRAN GO --------------------------------------
on my app side- i've already ensured the datatypes match up and the sizes are all ok (except for member_id, the variable is an int and i pass it as a small_int- the number is ranging from 1000-10000).
I am using SQLDMO to implement a tool to do basic management/script running for a MSDE database. The problem i am having is getting the number of rows affected from insert,update,delete statements. Help and MSDN seem to imply that this info is returned in a QueryResults object, but it is always empty unless the query is a select statement. I tried using ExecuteImmediate, ExecuteWithResults, and ExecuteWithResultsAndMessages methods and the info is not in any resultset, message, or property.
i read from help files that "For UPDATE, INSERT, and DELETE statements, the return value is the number of rows affected by the command. " Anyone know how to get the return value from the query below?
Below is the normal way i did in vb.net, but how to check for the return value. Please help.
======== Public Sub CreateMySqlCommand(myExecuteQuery As String, myConnection As SqlConnection) Dim myCommand As New SqlCommand(myExecuteQuery, myConnection) myCommand.Connection.Open() myCommand.ExecuteNonQuery() myConnection.Close() End Sub 'CreateMySqlCommand ========
<!-- Trying to create a GridView Survey form: Hi [User] Do you have these assets? [Gridview] Tag Number Response 123 [Yes ] [No] [Comments textbox] 234 [Yes ] [No] [Comments textbox]
Goal: The desire is for the user to click Yes or No and have the database updated with the user's name, date, response and any comments.
So far, I have created SqlDataSource with Select and Update commands, created the gridview and response buttons, setup the RowCommand and On_Updating Functions.
Problems:1) If I call the update() function for SqlDataSource1 and misuse the Defaultvalue parameters to run the sql, no update is posted to the database.
2) If I use the On_Update function to set the parameter values, I get "Data type mismatch in criteria expression." (Additionally, the On_Update function runs twice which I don't understand)Can anyone tell me what/why? (and how to fix it?)Sorry for the deluge, but here is the code: -->
<%@ Page Language="VB" %> <html> <head id="Head1" runat="server"> <title>Asset Survey</title> </head> <SCRIPT runat="server"> Protected Sub SqlDataSource1_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) Handles SqlDataSource1.Selecting e.Command.Parameters("Name1").Value = User.Identity.Name End Sub
Protected Sub SqlDataSource1_Updating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles SqlDataSource1.Updating 'For some reason, this function executes twice '2nd execution gets error: "Data type mismatch in criteria expression." 'e.Command.Parameters("PrimaryKey1").Value = intPrimaryKey 'e.Command.Parameters("Responder1").Value = strUser 'e.Command.Parameters("ResponseDate1").Value = dtModDate 'e.Command.Parameters("Response1").Value = strResponse 'e.Command.Parameters("ResponseComments1").Value = strComments End Sub
Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) _ Handles GridView1.RowCommand Dim GridRow1 As Integer = Convert.ToInt32(e.CommandArgument) If e.CommandName = "UpdateYes" Then 'code here to disable buttons and textbox '...
SqlDataSource1.UpdateParameters("Response1").DefaultValue = "Yes" End If
If e.CommandName = "UpdateNo" Then 'code here to disable buttons and textbox '...
SqlDataSource1.UpdateParameters("Response1").DefaultValue = "No" End If
'if I use the SqlDataSource1_Updating function, I get the mismatch error 'but if I (mis)use the DefaultValue parameter, no update occurs. SqlDataSource1.UpdateParameters("ResponseComments1").DefaultValue = _
SqlDataSource1.Update() 'Error Here if I use on_updating: "Data type mismatch in criteria expression." Catch except As Exception ' Handle the Exception. End Try End Sub
</SCRIPT> <body> <form id="formInv" runat="server"> <div> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:LocalTestMDB %>" ProviderName="<%$ ConnectionStrings:LocalTestMDB.ProviderName %>" SelectCommand="SELECT [PrimaryKey], [Name], [AssetTag], [Response], [Responder], [ResponseDate],[ResponseComments] FROM [Tablename] WHERE ([Name] = ?) ORDER BY [Login Name], [AssetTag]" UpdateCommand="Update [Tablename] SET [Response]=@Response1, [Responder]=@Responder1, [ResponseDate]=ResponseDate1, [ResponseComments]=ResponseComments1 WHERE [PrimaryKey]=@PrimaryKey1" OnSelecting="SqlDataSource1_Selecting" OnUpdating="SqlDataSource1_Updating"> <SelectParameters>
I seem to have a strange problem in that my code runs fine, but I am trying to INSERT rows into a database, and the rows affected by the INSERT command is alwsy zero, even though no error is thrown. Hence no data gets inserted.
Here is the code:
void recordTick(string pair, DateTime time, decimal sell, decimal buy)
{
SqlConnection thisConnection = new SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\FOREX.mdf;Integrated Security=True;User Instance=True");
insert = "INSERT INTO " + pair + " VALUES(" +
"'" + time.ToString("yyyy-MM-dd HH:mms") + "'," +
"'" + sell.ToString() + "'," +
"'" + buy.ToString() + "'" + ")";
thisConnection.Open();
SqlCommand command = new SqlCommand(insert, thisConnection);
The database is type .MDF that I created with the Project/Add Component/SQL Database menu. I can inspect it easily in Server Exporer and add data manually with no problem.
Can any one suggest how to get the INSERT to actually add the data?
I use business logic layer, TableAdapter(middle tier) and StoredProcedure(backend). In my stored procedure,I set as follows:set nocount offWhat and where should I do in order to get the rows affected count in the business logic layer(C#/VB code)?Thank you.
I'm doing an executenonquery() and the value I'm getting back is -1 This is confusing me, as sometimes the row has updated when I look at it in sql manager and then I look at it again and it seems to have reverted.Would it be possible to point me in the right direction for the cause and how to rectify / debug this issue. I'm using a stored procedure and I'm slightly uncertain how to check exactly what sql server has been told to insert ;) Thanks!
After executing a restore command. I got the following result. Anyone know why is displaying rows affected. I saw the executiong plan and it shows several execution plans? Its the first time i see it. Can anyone explain what is going on?
restore database test_GG_ATRECORDING_QAT2 from disk = 'f:a.bak' with move 'a' to 'f:MSSQL$INAQATdataa2.mdf', move 'a_log' to 'f:MSSQL$INAQATdataa2_log.LDF'
Processed 11016 pages for database 'test_GG_ATRECORDING_QAT2', file 'a' on file 1. Processed 1 pages for database 'test_GG_ATRECORDING_QAT2', file 'a_log' on file 1.
I was racking my brains trying to figure out why SomeCommand.ExecuteNonQuery() was not returning any rows... SQL Server 2005 likes to put the SET NOCOUNT ON statement in every stored procedure you write. By hiding the count of records touched by your query, you also disable the results to be consumed by your application. So I don't recommend using this statement for your stored procedures and ASP.NET applications, as this functionality is fairly critical for error trapping.
I am using a cursor to navigate on data...of a table.... inside the while @@fetch_status = 0 command I want to delete some rows from the table(temporary table) in order to not be processed... The problem is that I want this deletion to affect the rows the cursor has.
I have a database table where upon inserting a new record, I get 1 row(s) affected twice. But when deleting the record, I only get one instance of that message. I'm not really an expert, neither have I designed the database, but how can I retrieve the actual affected rows or determine what table does the other row pertain to?
When I use ExecuteNonQuery() with the stored procedure below it returns -1. However, when i tried to get rid of the if/else statements and just leave one insert statement for testing purposes, ExecuteNonQuery() returns the correct affected rows which is 1. So it seems like ExecuteNonQuery() doesn't work when the INSERT statement is inside the IF..ELSE. Can anybody help me with this problem? I haven't tried using @@RowCount because I really want to use ExecuteNonQuery() to do this because I don't want to rewrite my DAL. Thanks in advance -- With if/else ExecuteNonQuery returns -1ALTER PROCEDURE [dbo].[SP_AddObjectContribution] @ObjectId int, @FanId int, @DateContributed DateTime, @Notes nvarchar(512), @ObjectType intASBEGIN BEGIN TRAN IF @ObjectType = 2 BEGIN INSERT INTO FighterContributions (FighterId, FanId, DateContributed, Notes) VALUES (@ObjectId, @FanId, @DateContributed, @Notes) END ELSE IF @ObjectType = 3 BEGIN INSERT INTO FighterPhotoContributions (FighterPhotoId, FanId, DateContributed, Notes) VALUES (@ObjectId, @FanId, @DateContributed, @Notes) END ELSE IF @ObjectType = 4 BEGIN INSERT INTO OrganizationContributions (OrganizationId, FanId, DateContributed, Notes) VALUES (@ObjectId, @FanId, @DateContributed, @Notes) END ELSE IF @ObjectType = 5 BEGIN INSERT INTO EventContributions (EventId, FanId, DateContributed, Notes) VALUES (@ObjectId, @FanId, @DateContributed, @Notes) END ELSE IF @ObjectType = 6 BEGIN INSERT INTO FightContributions (FightId, FanId, DateContributed, Notes) VALUES (@ObjectId, @FanId, @DateContributed, @Notes) END ELSE IF @ObjectType = 7 BEGIN INSERT INTO FightPhotoContributions (FightPhotoId, FanId, DateContributed, Notes) VALUES (@ObjectId, @FanId, @DateContributed, @Notes) END IF @@ERROR <> 0 BEGIN ROLLBACK RETURN END COMMIT TRANEND -- Without if/else ExecuteNonQuery returns 1ALTER PROCEDURE [dbo].[SP_AddObjectContribution] @ObjectId int, @FanId int, @DateContributed DateTime, @Notes nvarchar(512), @ObjectType int AS
BEGIN
BEGIN TRAN INSERT INTO FighterContributions (FighterId, FanId, DateContributed, Notes) VALUES (@ObjectId, @FanId, @DateContributed, @Notes) IF @@ERROR <> 0 BEGIN ROLLBACK RETURN END
I have a file which has some wind data that i am trying to import into a sql data base through bulk insert. if the script works as it supposed i should see 144 rows impacted but i see 0 rows affected.
BULK INSERT TOWER.RAWINTERFACE_1058 FROM 'C:Temp900020150427583.txt' WITH(CHECK_CONSTRAINTS,CODEPAGE='RAW',DATAFILETYPE='char',FIELDTERMINATOR=' ',ROWTERMINATOR=' ',FIRSTROW=172)
The code works if the file is large but if its small 0 rows are affected. and also if i remove the header rows then the file works again. want to understand what is going on here. i am including the screen shot of the file in notepad++. I have tried changing the row terminator to ' ' , ' ' and also tried to change the codepage but nothing seems to work. No error file is being generated either, if i give a error file option.
I need to remove "rows affected" text from results as shown below from posted Sp. I am using set nocount on but its not working as expected.
Create Procedure DailyCheckList As SET NOCOUNT ON Declare @EmailSub varchar(500),@dt varchar(100),@Msg varchar(max),@M varchar(max) set @dt= convert(varchar(20),GETDATE(),107)
Hello. I was using the new sys.dm_db_index_operational_stats function which is nice for seeing counts of insert/update/delete actions per table index, bla bla bla... Anyways, question, can I do the same thing with Profiler? meaning, can I trace stored procs and sopmehow see the proc exec WITH each table it does actions against? Not talking about filtering on table names in the text, talking I just want to run an application, which uses all stored procs, and see every table used by that execution of the proc, and also the number of rows inserted,updated,deleted.... If so, which Profiler events/columns must I flick on to gather that? Thanks, Bruce
I run the following statement and it will not update beyond 7 million plus rows and I have about 38 million to complete. I keep checking updated row counts and after 1/2 day it's still the same so I know something is wrong because it was rolling through no problem when I initiated it. I need to complete ASAP so it's adding to my frustration. The 'Acct_Num_CH' field is an encrypted field (fyi).
SET rowcount 10000 UPDATE [dbo].[CC_Info_T] SET [Acct_Num_CH] = 'ayIWt6C8sgimC6t61EJ9d8BB3+bfIZ8v' WHERE [Acct_Num_CH] IS NOT NULL WHILE @@ROWCOUNT > 0 BEGIN SET rowcount 10000 UPDATE [dbo].[CC_Info_T] SET [Acct_Num_CH] = 'ayIWt6C8sgimC6t61EJ9d8BB3+bfIZ8v' WHERE [Acct_Num_CH] IS NOT NULL END SET rowcount 0
I want to retrieve some data in my gridview using a sqldatasource. Here's the idea. My Gridview contains events. A user can subscribe into one of them. When he subscribes, the event must be removed in the gridview. So when there is a subscription from that certain user for that event, it may not appear. Here's my not working code..SELECT Event.EventID,Event.name, Event.LocationID, Event.Date, Event.StatusFROM Shift INNER JOIN Event ON Shift.EventID = Event.EventID INNER JOIN Subscription ON Shift.ShiftID = Subscription.ShiftIDWHERE (Subscription.UserID <> @UserID) Greetz
I am using a sqlDataSource to read my query and to put the rows into a gridview. Now I want to read just a couple of rows from my query based on a maximum number, also defined in the table. I have absolutely no idea how to do that..for example: I want to view only the 10 most recent subsciptions into my gridview. The subscriptions are stored into tabel Subscriptions which has values id, userid,date. Table Event has a parameter "maximum subscriptions" (which is 10 in my example) I hope it is clear enough?Thank you in advance!BlueiVeinz
I have a SqlDataSource that I need to remove the first 3 rows from before it is bound to a GridView. How would I go about doing this? (if I could remove them at the db level in the sproc I would, but right now that is not an option - so I need to do it once I've already received the data) Thanks.
Hi All, I am new to development of asp. I have an SQLDataSource set as the data source for a grid view. When I click on the edit link in the Gridview, change the data, and click update, the old data is still displayed in the row. I found exact same issue as here -- http://forums.asp.net/thread/1217014.aspx Solution in the above thread is to add this { if (reader != null) reader.Close(); } conn.Close(); How do I apply above solution in my situation ?
I am updating through stored procedure.and don't have code at background. My code is Datasource : <asp:SqlDataSource ID="ds" runat="server" ConnectionString="<%$ ConnectionStrings:ds %>"
I am trying to update a field in gridview. My update is not working, sort of. The original value is being updated with a NULL value when I click on the update button.here is my code <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource2" AutoGenerateEditButton="True" DataKeyNames="rqt_id">UpdateCommand="UPDATE [rqt_data] SET [rqt_title]=@rqt_title WHERE [rqt_id] = @rqt_id" > <asp:Parameter Name="rqt_title" Type="String" /> the field rqt_title is set up as a NVarChar(25) in the db. I can't specify that for the Type property. Could that be the issue?thx
I want to write the results of a checkbox to my database, but I am stuck on the syntax? Here's what I have so far, could somebody pleae help., my aim is to not show a line when checkbox ticked, not to actually delete the record from the database
Hi, The problem that I have now is that yes I want to delete from gridview, but I still want the old record to be in database ,not deleted. Does anybody know how I can evaluate my checkbox, and update to the database the results of the checkbox,I am not sure of the update syntax?string strsql = "update * from jobs order by ID asc"; SqlConnection conn = new SqlConnection(ConnectionString); SqlDataAdapter ad = new SqlDataAdapter(strsql, conn);DataSet ds = new DataSet();ad.Fill(ds, "TASKS"); GridView1.DataSource = ds; GridView1.DataBind(); got stuck here, basically I cant work out how to evauate the results of a checkbox, and write back to the database, can anybody help?
design view is great, just drag on a gridview make it link to my database and poof there is all my data! I can even click the "allow editting button" and poof I can edit my data. But how do assign validation rules? because atm if someone tries to edit my name field at puts in "asdfasdkfhdsgasdgaga" which is too long, clicks update it goes to a horrible error page. How can I catch these errors and make a nice message instead?
I may have posted this in the wrong forum before, but i am trying to update a table in SQL2000 from asp.net2.0 gridview. I follow all the recommended ways and it doesnt update the row. Please help <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" DataKeyNames="ID" CellPadding="4" ForeColor="#333333" GridLines="None">
Hi GutysI am having problem with my UPDATE in GridView, it is saying that I have too many argument, I don't This happens when I click the UpdateCommand in GRIDVIEW Procedure or function UpdateCountry has too many arguments specified.<asp:SqlDataSource ID="mySqlDataSource" Runat="server" SelectCommandType="StoredProcedure" SelectCommand="ShowCountry" UpdateCommandType="StoredProcedure" UpdateCommand="UpdateCountry" ConnectionString="<%$ ConnectionStrings:ConnString %>"> <UpdateParameters> <asp:Parameter Type="String" Name="CountryName"></asp:Parameter> <asp:Parameter Type="String" Name="CountryID"></asp:Parameter> </UpdateParameters> </asp:SqlDataSource>Just In case these are my Stored Procedures**************************************************************************CREATE PROCEDURE [dbo].[UpdateCountry] @CountryName varchar(50),@CountryID varchar(50)ASUPDATE EkeanyanwuO.tCountry SET [CountryName] = @CountryName WHERE [CountryID] = @CountryIDGO************************************************************************************CREATE PROCEDURE [dbo].[ShowCountry] ASSELECT TOP 100 PERCENT EkeanyanwuO.tIMSREGION.ImsRegionName AS ImsRegionName, EkeanyanwuO.tCountry.CountryName AS CountryName, EkeanyanwuO.tIMSREGION.ImsRegionID AS ImsRegionID, EkeanyanwuO.tCountry.CountryID AS CountryIDFROM EkeanyanwuO.tCountry INNER JOIN EkeanyanwuO.tIMSREGION ON EkeanyanwuO.tCountry.ImsRegionID = EkeanyanwuO.tIMSREGION.ImsRegionIDORDER BY EkeanyanwuO.tCountry.CountryNameGO************************************************************************************
I try to calculate a field value and update other. It almost worksUPDATE t_Shopping_cart SET [Product_code] = @Product_code, [Quantity] = @Quantity, [Total] = Quantity * Price WHERE ([Product_code] = @Product_code)I try to update t_Shopping_cart table with quantity values from grid view and calculate sum of products (quantity*Price). Best I can get is that quantity values are old. Some comments about my query:Price is also a field in table and control. [Product_code] = @Product_code part is probably not needed. Any ideas?Leif
Hi all,Happy New Year!I've just install VS .NET 2005 and try to play with Gridviewwhen I configure the datasource for Gridview and click "Advance" in order to enable Update, Delete Select etc...the checkBox is not selectableCan someone pls show me how?Thanks in advance.