4. Add the event handler for the button in code behind.
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.SqlDataSource1.Insert()
End Sub
5. Run the page, enter some text into the textboxes and hit the button. WHOOT!? This time it doesn't work and the following error appears:
Cannot insert the value NULL into column 'CommentAuthor', table 'C:DOCUMENTS AND SETTINGSSONYMY DOCUMENTSVISUAL STUDIO 2005WEBSITESCOMMENTSAPP_DATACOMMENTS_DB.MDF.dbo.Comments'; column does not allow nulls. INSERT fails.
The statement has been terminated.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Cannot insert the value NULL into column 'CommentAuthor', table 'C:DOCUMENTS AND SETTINGSSONYMY DOCUMENTSVISUAL STUDIO 2005WEBSITESCOMMENTSAPP_DATACOMMENTS_DB.MDF.dbo.Comments'; column does not allow nulls. INSERT fails.
The statement has been terminated.
Source Error:
Line 4:
Line 5: Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Line 6: Me.SqlDataSource1.Insert()
Line 7: End Sub
Line 8: End Class
Source File: C:Documents and SettingsSONYMy DocumentsVisual Studio 2005WebSitesComments2.aspx.vb Line: 6
So can anyone explain why this only works in the first example?
Hello, I'm new to the forum and new to SQL, ASP.NET, etc. I am creating an intranet site for my company in VS 2005 and have run into a very annoying problem that I can't seem to solve. I have tried Googling it and came up empty. I have a database in SQL Express 2005 and my website will be accessing several tables within the database. I can retrieve info just fine and I can update, delete, etc just fine using gridview or other prebuilt tools, but when I add a few text boxes and wire a button to the SqlDataSource.Insert() command, I get a new record that is full of null values except for the identity key I have set. The kicker is that I am also using a master page and when I duplicate the web page without the master page link, everything works just fine. The following snippets show what I'm doing:<InsertParameters><asp:FormParameter Name="Name" Type="String" FormField="txtName" /><asp:FormParameter Name="Location" Type="String" FormField="ddlLocation" /><asp:FormParameter Name="Issue" Type="String" FormField="txtProblem" /></InsertParameters>Of course I match the formfields to the text boxes, create an onclick event for my button, the sqldatasource is configured correctly, it just doesn't work with the master page no matter what I do. Any help would be appreciated. Thanks
hi friends, I created sqldatasource control. In select command i written the query like this "select * form emp" and bounded in grid.How can I change the query for searching the details according the date wise when i click the search button.
Hello experts i have a SqlDataSource Control on my web form. Here is the source for the control <asp:SqlDataSource ID="sqlSearchDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:DbefomsConnectionString %>" SelectCommand="SELECT [icon], [file_name], [path] FROM [tblfile] WHERE ([file_name] = @file_name)"> <SelectParameters> <asp:ControlParameter ControlID="txtSearch" DefaultValue="0" Name="file_name" PropertyName="Text" Type="String" /> </SelectParameters> </asp:SqlDataSource> This control displays icon, file_name, path in GridView Control The problem is How can i store the above field values in an asp.net variable. Thanks Regards Ali
Do you have to use the sqldatasource in conjuction with another control like gridview or dropdown list? I'd like to check to see if a record exists in one table before inserting data into another.
Hello.I'm new to ASP.NET and trying to write data to a Microsft SQL Server. I have created a SqlDataSource control, which is 'connected' to my SQL server.Now my question is how i can put data in the database throw the control, and read data from it. I've read the site, but it's still unclear for me..Greetings!
Hello: I am having a little issue with an error that is frustrating me. I have a SqlDataSource within an asp:label control and also have a two dropdownlists inside that asp:label control also. When I select from the first dropdownlist, it should enable the second dropdownlist with the populated data, but instead I receive. The SqlDataSource control 'sqlGetMLSByCity' does not have a naming container. Ensure that the control is added to the page before calling DataBind. Any ideas why this would be? Here is the web from portion: <asp:Label ID="recip_form_request" runat="server" Visible="false"> <ul> <li>Step one: Select listing type.</li> <li>Step two: Select the City that you are reciprocating to.</li> <li>Step three: Complete the Recip Form.</li> </ul> <asp:DropDownList ID="recip_form_type" runat="server" AutoPostBack="true" Visible="False"> <asp:ListItem Value="0" Text="(Select Form)"></asp:ListItem> <asp:ListItem Value="1" Text="Residential"></asp:ListItem> </asp:DropDownList> <br /> <asp:DropDownList ID="outside_assoc_cities" runat="server" AutoPostBack="True" Enabled="False" DataTextField="city" DataValueField="id" Visible="False"></asp:DropDownList><br /> <asp:Label ID="city_mls_desc" runat="server"></asp:Label><br /> <asp:Button ID="page1_btn" runat="server" Text="Next >>" Visible="False" /> <asp:SqlDataSource ID="sqlCities" runat="server" ProviderName="System.Data.SqlClient" ConnectionString="<%$ AppSettings:connectionstring %>" SelectCommandType="Text" SelectCommand="SELECT id, city FROM tCityMaster"></asp:SqlDataSource> <asp:SqlDataSource ID="sqlGetMLSByCity" runat="server" ProviderName="System.Data.SqlClient" ConnectionString="<%$ AppSettings:connectionstring %>"> <SelectParameters> <asp:ControlParameter ControlID="outside_assoc_cities" Name="City" /> </SelectParameters> </asp:SqlDataSource></asp:Label> then the code behind: Protected Sub outside_assoc_cities_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles outside_assoc_cities.SelectedIndexChanged If outside_assoc_cities.SelectedIndex > -1 Then Dim ItemId As Integer = Integer.Parse(outside_assoc_cities.SelectedValue) Dim MLSID As String = Nothing Dim cmd As New SqlCommand Dim con As New SqlConnection cmd.Connection = con Dim sqlGetMLSByCity_sql As SqlDataSource = CType(Page.FindControl("sqlGetMLSByCity"), SqlDataSource) 'using connectionstring from SqlDataSource Control con.ConnectionString = sqlGetMLSByCity_sql.ConnectionString 'con.ConnectionString = sqlGetMLSByCity.ConnectionString cmd.CommandType = CommandType.Text cmd.CommandText = "SELECT mls_id FROM pwaordev..tCityMaster WITH(NOLOCK) WHERE ID=@ID" cmd.Parameters.Add("@ID", SqlDbType.Int, 4).Value = ItemId Try con.Open() MLSID = cmd.ExecuteScalar con.Dispose() cmd.Dispose() Catch ex As Exception con.Dispose() cmd.Dispose() Response.Write(ex.ToString()) End Try 'Further logic to display button depending on MLS If Not String.IsNullOrEmpty(MLSID) Then If MLSID = "B" Then city_mls_desc.Text = "The MLS system that covers " & outside_assoc_cities.SelectedItem.Text & " is Greater South Bay MLS." page1_btn.Visible = True ElseIf MLSID = "A" Then city_mls_desc.Text = "The MLS system that covers " & outside_assoc_cities.SelectedItem.Text & " is Big Bear BOR, MLS, which is not covered by Pacific West Association of REALTOR®, please contact us for more information." page1_btn.Visible = False ElseIf MLSID = "C" Then city_mls_desc.Text = "The MLS system that covers " & outside_assoc_cities.SelectedItem.Text & " is Combined L.A./Westside MLS." page1_btn.Visible = True ElseIf MLSID = "F" Then city_mls_desc.Text = "The MLS system that covers " & outside_assoc_cities.SelectedItem.Text & " is Crisnet MLS, which is not covered by Pacific West Association of REALTOR®, please contact us for more information." page1_btn.Visible = False ElseIf MLSID = "Y" Then city_mls_desc.Text = "The MLS system that covers " & outside_assoc_cities.SelectedItem.Text & " is DCAoR - Yucca Valley Area, which is not covered by Pacific West Association of REALTOR®, please contact us for more information." page1_btn.Visible = False ElseIf MLSID = "D" Then city_mls_desc.Text = "The MLS system that covers " & outside_assoc_cities.SelectedItem.Text & " is Desert Area MLS." page1_btn.Visible = True ElseIf MLSID = "L" Then city_mls_desc.Text = "The MLS system that covers " & outside_assoc_cities.SelectedItem.Text & " is i-Tech Glendale/Pasadena." page1_btn.Visible = True ElseIf MLSID = "M" Then city_mls_desc.Text = "The MLS system that covers " & outside_assoc_cities.SelectedItem.Text & " is MRM - Multi-Regional MLS." page1_btn.Visible = True ElseIf MLSID = "R" Then city_mls_desc.Text = "The MLS system that covers " & outside_assoc_cities.SelectedItem.Text & " is RIM - Rim of the World MLS, which is not covered by Pacific West Association of REALTOR®, please contact us for more information." page1_btn.Visible = False ElseIf MLSID = "G" Then city_mls_desc.Text = "The MLS system that covers " & outside_assoc_cities.SelectedItem.Text & " is SDI - San Diego, which is not covered by Pacific West Association of REALTOR®, please contact us for more information." page1_btn.Visible = False ElseIf MLSID = "S" Then city_mls_desc.Text = "The MLS system that covers " & outside_assoc_cities.SelectedItem.Text & " is SOCAL MLS - Southern California MLS." page1_btn.Visible = True ElseIf MLSID = "T" Then city_mls_desc.Text = "The MLS system that covers " & outside_assoc_cities.SelectedItem.Text & " is Outside Area, which is not covered by Pacific West Association of REALTOR®, please contact us for more information." page1_btn.Visible = False End If 'test.Text = MLSID 'If test.Text = "L" Then 'mls_text.Text = "i-Tech" 'End If End If End If End Sub Any help would be great, thank you!
I have an SqlDatSource that I have fully setup at design time, but I don't want it to open and load as soon as the page loads, instead I want to open it based on a condition. How do you do that with a DataSource? I know that I can simply remove the Select query, and then set it at run time, but I'm looking for something better, that allows me to have the Select query set at design time, in part because I have a lot of parameters.
Hello: I have two SqlDataSource controls on two different pages: one is updating a table and the other is reading from the same table. Now is it possible that the reader SqlDataSource control can be refreshed immediately (to reflect updates) when the other control updates the table?
Hello all, I am trying to update the record which involed the modification of key in Datakeynames, but when i click the update button from gridview, it doesn't allow to change the value of modified column. <asp:SqlDataSource ID="SqlDataSource1" runat="server" DataSourceMode="DataSet" ConnectionString="<%$ ConnectionStrings:WebsiteDataConnection %>" OldValuesParameterFormatString="old_{0}" SelectCommand="SELECT * FROM [ServiceAgents]" InsertCommand="INSERT INTO ServiceAgents VALUES(@Ser_STATE, @Ser_CITY, @Ser_AGENT, @Ser_PHONE, @Ser_EQUIPMENT)" UpdateCommand="UPDATE ServiceAgents SET AGENT=@AGENT, PHONE=@PHONE WHERE (STATE=@STATE and CITY=@CITY and AGENT=@old_AGENT and EQUIPMENT=@EQUIPMENT)" DeleteCommand="DELETE FROM ServiceAgents WHERE (STATE=@STATE and CITY=@CITY and AGENT=@AGENT and EQUIPMENT=@EQUIPMENT)" > <UpdateParameters> <asp:Parameter Type="String" Name="AGENT" /> <asp:Parameter Type="String" Name="PHONE" /> <asp:Parameter Name="old_AGENT" /> <asp:Parameter Type="String" Name="STATE" /> <asp:Parameter Type="String" Name="CITY" /> <asp:Parameter Type="String" Name="EQUIPMENT" /> </UpdateParameters> <InsertParameters> <asp:ControlParameter Name="Ser_STATE" ControlID="TextBox_state"/> <asp:ControlParameter Name="Ser_CITY" ControlID="TextBox_city"/> <asp:ControlParameter Name="Ser_AGENT" ControlID="TextBox_agent"/> <asp:ControlParameter Name="Ser_PHONE" ControlID="TextBox_phone"/> <asp:ControlParameter Name="Ser_EQUIPMENT" ControlID="TextBox_equip" /> </InsertParameters> <DeleteParameters> <asp:Parameter Type="String" Name="STATE" /> <asp:Parameter Type="String" Name="CITY" /> <asp:Parameter Type="String" Name="AGENT" /> <asp:Parameter Type="String" Name="EQUIPMENT" /> </DeleteParameters> </asp:SqlDataSource> Does anyone got any ideas about it? Where is wrong in the control?
I have a SQLDatasource control on a web page. It is the datasource for a gridview control.I want the gridview to show all jones if the FirstName textbox is left blank or empty. Right now I have to put a % in the FirstName textbox to get what I want. If I make the FirstNameTextBox empty or remove the % from the FirstNameTextbox it returns all the names in the database no matter what the last name is.How do I get it to work without having to use the % in the FirstName Textbox? THANKS!FilterExpression="LastName LIKE '%{0}%' and FirstName LIKE '%{1}%'"><FilterParameters> <asp:ControlParameter ControlID="LastNameTextBox" Name="LastName" PropertyName="Text" DefaultValue="" /> <asp:ControlParameter ControlID="FirstNameTextBox" Name="FirstName" PropertyName="Text" DefaultValue="" /></FilterParameters> Last Name: Jones___________First Name: %_____________FILTERBUTTON GridviewLast Name First NameBob JonesBill Jones
I have not found anything useful on the Wizard control. Anything I can find gets to the last step and then just takes the info you supplied and applies them to a bunch of Label.Text's - none that do work. So I am building a Wizard control for an HR system that will insert the information into SQL through a SqlDataSource. The problem is, only the controls that are present in whichever step is currently selected in VWD will appear in the Command and Parameter Editor. I tried to work around it by selecting the first step, then applying the controls in step 1 within the Parameter Editor, but when I go back to do step 2, it erases everything I just did for step 1. How do I implement the Wizard with a SqlDataSource?
I have a gridview that is tied to a SQLDataSource control. As the gridview is filled some of the ASPX code calls some code in the code behind page. Where I am having trouble is that in one of these calls I need to some how pass the id filed ("LISTID")of the table for the SQL statement in the code behind page and I'm not sure how to do it. The code behind function is always using the same id and I do not know how to change it. Below is all the code.
Here is the calling code in the ASPX page. "DeleteBtn" Visible='<%# IsDeleteBtnVisible %>' runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" ForeColor="#003399"> Here is the entire ASPX code. class="header"> class="title">My Lists "Span1"> Current List Filter: "DropDownList2" cssclass="filterdropdown" AutoPostBack="true" runat="server"> "Active" Value="False"> "Done" Value="true"> --------------------------------------------------------------------------------"separator2"/> "list2"> "ScriptManager1" EnablePartialRendering="true" runat="server"> "Up2" UpdateMode="Conditional" runat="server"> "GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="LISTID" DataSourceID="SqlDataSource1" AllowPaging="True" AllowSorting="True" EnableViewState="False" GridLines="None" AlternatingRowStyle-BackColor="#FFFFCC" AlternatingRowStyle-Font-Size="Small" ForeColor="#FFFFCC" Font-Size="Small" AlternatingRowStyle-ForeColor="Black" Width="100%" HeaderStyle-ForeColor="White"> "False"> "LinkButton1" runat="server" CausesValidation="True" CommandName="Update" Text="Update" ForeColor="#003399"> "LinkButton2" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" ForeColor="#003399"> "LinkButton1" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" ForeColor="#003399"> "DeleteBtn" Visible='<%# IsDeleteBtnVisible %>' runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" ForeColor="#003399"> "buttons"> "commands"> "ITEM_DETAILS" HeaderText="Details" SortExpression="ITEM_DETAILS" ControlStyle-ForeColor="#003399"> "name_edit"> "name"> "name"> "Pri" itemStyle-HorizontalAlign="Center" SortExpression="Priority" ControlStyle-ForeColor="#003399"> "DropDownList1" Width="75" SelectedValue='<%# Bind("Priority") %>' runat="server"> "High" Value="3"> "Medium" Value="2"> "Low" Value="1"> "pri" Text='<%# FormatPriority(Eval("Priority")) %>' runat="server"> "priority"> "#003399"> "priority"> "DUEDATE" itemStyle-HorizontalAlign="Center" HeaderText="Due Date" DataFormatString="{0:MM/dd/yyyy}" SortExpression="DUEDATE" > "Center"> "COMPLETEDON" itemStyle-HorizontalAlign="Center" HeaderText="Completed On" DataFormatString="{0:MM/dd/yyyy}" SortExpression="COMPLETEDON" > "Center"> "Done" itemStyle-HorizontalAlign="Center" SortExpression="IsComplete"> "CheckBox1" runat="server" Checked='<%# Bind("IsComplete") %>'> "iscomplete"> "iscomplete"> "Done" Text='<%# FormatDone(Eval("IsComplete")) %>' runat="server"> "Button2" runat="server" CommandName="Something" DataTextField="LISTID" DataTextFormatString="{0} active items" text='<%# Eval("LISTID") %>'> "Empty">No lists "White"> "#FFFFCC" Font-Size="Small" ForeColor="Black"> "Div1"> "Up3" UpdateMode="Conditional" runat="server"> Add New List: "AddItem2" cssclass="newitem" runat="server"> "Button1" runat="server" OnClick="AddListBtn_Click" Text="Add"> "txtdate" runat="server"> "Button1" EventName="Click"> "SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:FastTrackConnectionString %>" SelectCommand="SELECT * FROM [TODO]"> Here is the code behind page code. Protected Function IsDeleteBtnVisible() As Boolean ' Return IIf(itemCount = 0, True, False) 'This is for my gridview Dim strConn2 As SqlConnection = New SqlConnection Dim cmd2 As SqlCommand = New SqlCommand Dim rs2 As SqlDataReader Dim test1 As String Dim test2 As String strConn2.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("FastTrackConnectionString2").ToString() strConn2.Open() cmd2.Connection = strConn2 cmd2.CommandText = "SELECT LISTID, (SELECT COUNT(0) AS ItemCount FROM TODO_SUB_ITEMS WHERE(LISTID = TODO.LISTID) AND (ISCOMPLETE ='False')) AS ItemCount FROM TODO WHERE (ISCOMPLETE ='False')" rs2 = cmd2.ExecuteReader() rs2.Read() Dim testlistid As Integer = rs2(0) Dim intholder As Integer = rs2(1) strConn2.Close() cmd2 = Nothing strConn2 = Nothing Return IIf(intholder = 0, True, False) End Function
I have a gridview that is filled from a SQLDataSource control when the page loads. I need to do some updates and delets on this data and I wanted to know can you add more than one SQL statement to a SQLDataSource control or do I have to have a seprate control for each operation? The SQL currently is just the standard SELECT *, I cannnot see a way to add statments. Thanks, Ty
There is something I don't understand or I am just missing something here. Why is it that I can place an SqlDataSource1.Insert() or update, or delete, but not an SqlDataSource.Select() inside a button click event "for an example" without getting an Compilation Error? Thanks, xyz789
I have dragged 3 SqlDataSource Controls to the WebDesigner and none are appearing graphically in the Designer View, but they are in the Source View. How can I get the control to appear in the designer.
When I configure a SQLDataSource control I want the following where clause... WHERE (RegionID = @RegionID AND DistrictID IS NULL AND CampusID IS NULL) OR (DistrictID = @DistrictID AND CampusID IS NULL ) OR(CampusID = @CampusID AND UserRole = 'CampusAdmin') OR (CampusID = @CampusID)but it gets reformated as.... WHERE (RegionID = 'Region10') AND (DistrictID IS NULL) AND (CampusID IS NULL) OR (DistrictID = 2) AND (CampusID IS NULL) OR (CampusID = '999999103') AND (UserRole = 'CampusAdmin') OR (CampusID = '999999103')I don't think these are functionaly equivelant, are they?If not how do I stop the 'wizard' from reformatting the SQL where clause?Thanks
I set up a Sqldatasource control in 2.0 and I can retrieve data through a SQL Server connection from a stored procedure. My problem is when I set up the insert command object through the wizard for the Sqldatasource control with another stored procedure for inserting data and call the insert method of my Sqldatasource object i get nothing not even an error it just goes through the code like nothing was wrong and I don't get anything inserted. I don't know if this could be a problem but one of the parameters in the stored procedure is declared like this: @return tinyint output. I don't know how the Sqldatasource accounts for return parameters. Here is the code for the insert for the Sqldatasource object.<asp:SqlDataSource ID="sdsMain" runat="server" ConnectionString="<%$ ConnectionStrings:SN_CUSTOMERConnectionString %>"InsertCommand="uspSNOrder_Promo_Live" InsertCommandType="StoredProcedure" SelectCommand="uspOPFillPromo"SelectCommandType="StoredProcedure"><InsertParameters><asp:ControlParameter ControlID="ddlPromo" Name="promoid" PropertyName="SelectedValue"Type="Int32" /><asp:Parameter DefaultValue="1" Name="datasourceid" Type="Int32" /><asp:Parameter DefaultValue="0" Name="datasourcekey" Type="String" /><asp:Parameter DefaultValue="9" Name="salesroomid" Type="Int32" /><asp:Parameter DefaultValue="9999" Name="userid" Type="Int32" /><asp:ControlParameter ControlID="txtFName" DefaultValue="" Name="firstname" PropertyName="Text"Type="String" /><asp:ControlParameter ControlID="txtLName" Name="lastname" PropertyName="Text" Type="String" /><asp:ControlParameter ControlID="txtAddress" Name="address" PropertyName="Text" Type="String" /><asp:ControlParameter ControlID="txtCity" Name="city" PropertyName="Text" Type="String" /><asp:ControlParameter ControlID="txtState" Name="state" PropertyName="Text" Type="String" /><asp:ControlParameter ControlID="txtZip" Name="zip" PropertyName="Text" Type="String" /><asp:ControlParameter ControlID="txtPhone" Name="phone" PropertyName="Text" Type="String" /><asp:ControlParameter ControlID="txtEmail" Name="email" PropertyName="Text" Type="String" /><asp:ControlParameter ControlID="ddlStatus" Name="status" PropertyName="SelectedValue"Type="Int32" /><asp:Parameter DefaultValue="0" Direction="InputOutput" Name="return" Type="Byte" /></InsertParameters></asp:SqlDataSource>Thanks in advance
Dear all,I am couping a dropdownlist and a sqldatasource control to display a column from a database of SQL/Server on browser. However, when I tried to configure the sqldatasource to let it get data from SQL/Server, it always report an error. It normally happens at the first step of creating new connection. After I specified the correct sql/server instance name, using SQL server authentication, and select a database name. Even the connection test can sucessfully passed. However, when I click the "OK" button, an error message saying "object reference not set to an instance of an object" popped out and I could not add new connections. The strange thing is that after I reintall the visual studio 2005 service pack 1. It will function properly for a while. After sometime, it will fail again. Anybody has suggestions? Thanks a lot!
I have made a SQLDataSource control with the select command: SELECT COUNT(*) AS 'Antall' FROM Utgivelse WHERE (medieID = @medieID) I want to use the "Antall" result programmatically in C# code. I try the following statement: IDataReader MyReader;
MyReader = CType(SqlDataSource2.Select(DataSourceSelectArguments.Empty),IDataReader); but it doesnot work. Can somebody help me how to get the data from th control ? Tom
Is it possible to place a stored procedure in a SQLDataSource control that needs a variable input then run it later? DETAILS I have 2 pages with gridview controls that are linked to a SQLDataSource controls. What I would like to do is when the user clicks on a link in the gridview of the first page I want to take the value of the link clicked and pass it to the second page where it is placed into a variable that would be used in a WHERE clause to fill the second pages gridview. I have no problem getting the value into a variable in the page load event of the second page. What I would be nice is since the gridview is already tied to a SQLDataSource control with the columns specified is if I could some how pass the variable to a stored procedure in the control so I don't have to manually pull and fill the data. Any thoughts would be apperciated. Thanks, Ty
I am trying to use a 'timestamp' type column with SQLDataSource for concurrency control with SQL Server. I'm getting the following error: Operand type clash: timestamp is incompatible with sql_variant It appears that the problem is that the value for the Type property of the Parameter (which was generated by the SqlDataSource wizard) is Object which maps to 'sql_variant' rather than to 'timestamp'. I know that the older way of doing things with SqlDataAdapter, SqlCommand, SqlParameter can handle timestamps because SqlParameter has a SqlDbType property that can have a value of SqlDbType.Timestamp, but I don't see how to do this with the newer SqlDataSource, Parameter classes because the Parameter.Type property (of type TypeCode) doesn't have a Timestamp value. Has anyone been able to use a 'timestamp' type field with SqlDataSource? Here's my sample code: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="MyTestPage.aspx.cs" Inherits="MyTestPage" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"><title>Untitled Page</title></head><body><form id="form1" runat="server"><div><asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"EmptyDataText="There are no data records to display." DataKeyNames="MyID"><Columns><asp:CommandField ShowEditButton="True" /><asp:BoundField DataField="MyID" HeaderText="MyID" InsertVisible="False" ReadOnly="True"SortExpression="MyID" /><asp:BoundField DataField="MyDesc" HeaderText="MyDesc" SortExpression="MyDesc" /></Columns></asp:GridView><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConflictDetection="CompareAllValues"ConnectionString="<%$ ConnectionStrings:CtrlConnectionString1 %>" DeleteCommand="DELETE FROM [MyTest] WHERE [MyID] = @original_MyID AND [MyDesc] = @original_MyDesc AND [timestamp] = @original_timestamp"InsertCommand="INSERT INTO [MyTest] ([MyDesc], [timestamp]) VALUES (@MyDesc, @timestamp)" OldValuesParameterFormatString="original_{0}"ProviderName="<%$ ConnectionStrings:CtrlConnectionString1.ProviderName %>" SelectCommand="SELECT [MyID], [MyDesc], [timestamp] FROM [MyTest]"UpdateCommand="UPDATE [MyTest] SET [MyDesc] = @MyDesc WHERE [MyID] = @original_MyID AND [MyDesc] = @original_MyDesc AND [timestamp] = @original_timestamp"><DeleteParameters><asp:Parameter Name="original_MyID" Type="Int32" /><asp:Parameter Name="original_MyDesc" Type="String" /><asp:Parameter Name="original_timestamp" Type="Object" /></DeleteParameters><UpdateParameters><asp:Parameter Name="MyDesc" Type="String" /><asp:Parameter Name="timestamp" Type="Object" /><asp:Parameter Name="original_MyID" Type="Int32" /><asp:Parameter Name="original_MyDesc" Type="String" /><asp:Parameter Name="original_timestamp" Type="Object" /></UpdateParameters><InsertParameters><asp:Parameter Name="MyDesc" Type="String" /><asp:Parameter Name="timestamp" Type="Object" /></InsertParameters></asp:SqlDataSource></div></form></body></html>
how can i display the result of an asp:SqlDataSource into a lable control.the sqldatasource returns the count for some thing ie "select count(*) as total from tbl"please help
Hi,I would like to upload images using an SQLDataSource Control with a DetailsView, so that users can update/insert/delete records.Can someone tell me how I can do this in VB.NET ?It seems that I'm the only one on the world trying to do this already with ASP.NET VWD 2005.Thanks to all....Bart
After some help from the folks in the Security forum, I have some of the answer I need. Hopefully someone here can help me figure out the best method of using that information to find a final solution. To start, here's a brief synapsis: I'm developing an App in ASP.NET 2.0, using forms-based authentication and the Login Control. I am able to login fine as far as I can tell, since I am able to proceed to the destinationURL without error. From there, I button click to the application in question. Here is where I have the problem. I want to run a select query on a SQL table where a field = the current user's Username. I cannot find any examples of doing this. I have managed to figure out how to retrieve the current user's username via the Membership.GetUser method, but I can't seem to figure out how to apply that to my SqlDataSource Control and get a valid response. a snippet of my control's code follows: <script runat="server"> - This is run inline, not code-behindProtected memUser As MembershipUser
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)memUser = Membership.GetUser()End Sub</script> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:SWGToolsetConnectionString %>"SelectCommand="SELECT [CharacterName] FROM [Characters] WHERE ([UserID] = '<% =Server.HtmlEncode(memUser.Username) %>')"></asp:SqlDataSource> If anyone can tell me what I can or should be doing differently, I would appreciate it.
I am using content and master pages. The content page has to query the database to get the master page name (among other things), which is done in ‘Page_PreInit’, and then the master page has to query the database to get some layout options, done in ‘Page_Load’.
Is it possible for the master page to use the existing open connection, or am I forced to close the connection in the content page and open up a new connection in the master page? I’ve tried various things without success. The second question is, does it matter? Will opening and closing two connections be much slower than opening and closing one?
I need to provide defaults and sometimes overrides for items in SQLDataSource's UpdateParameters. I am attempting to do this in a FormView's ItemUpdating and ItemInserting events as follows: //======================================================================== // FormView1_ItemUpdating: //======================================================================== protected void FormView1_ItemUpdating(object sender, FormViewUpdateEventArgs e) { // not sure if this is the bets place to put this or not? dsDataSource.UpdateParameters["UpdatedTS"].DefaultValue = DateTime.Now.ToString(); dsDataSource.UpdateParameters["UpdatedUserID"].DefaultValue = ((csi.UserInfo)Session["UserInfo"]).QuotaUserID; } In the example above I am attempting to set new values for the parameters which will replace the existing values. I have found that using the DefaultValue property works ONLY if there is no current value for the parameter. Otherwise the values I specify are ingnored.The parameters of an ObjectDataSource provide a Value property but SQLDataSource parameters do not.How can I provide an override value without needing to place the value in the visible bound form element???If you can answer this you will be the FIRST person ever to answer one of my questions here!!!Thanks,Tony
i use asp.net 2.0 and c# initially the dropdownlist control is bound to the queryA ("select * from tableA".) for sqldatasource1 now in a button click event, i want to change the query to queryB ("select * from tableA where id = @id".) in the code below, i can change the SELECT query of sqldatasource1 from queryA to queryB, but how can i give value to the parameter? please help protected void Button1_Click(object sender, EventArgs e) { sqldatasource1.SelectCommand = queryB }
I thought this would be easy. I have a repeater control and a sqldatasource control. I am trying to filter the select statement using DateTime.Now.ToString() and keep getting an invalid date string format. The control is on a content page in my asp.net site. On the master page this <%= DateTime.Now.ToLongDateString() %> works to display the current date. If I try and put <%= DateTime.Now.ToString() %> in the Default value of the SelectParameter it does not work. No intellisense either so I am assuming I am missing something. Here is the code... pretty basic really. <asp:Repeater ID="Repeater1" runat="server" DataSourceID="sqlDSnews"> <ItemTemplate> <h3><%# Eval("newTitle")%></h3> </ItemTemplate> </asp:Repeater> <asp:SqlDataSource ID="sqlDSnews" runat="server" ConnectionString="<%$ ConnectionStrings:XXXX%>" SelectCommand="SELECT [newTitle], [newsDetails], [dateExpires], [newsImage], [dateCreated] FROM [News] WHERE (([GroupID] = @GroupID) AND ([dateExpires] >= @dateExpires))"> <SelectParameters> <asp:QueryStringParameter DefaultValue="0" Name="GroupID" QueryStringField="Gid" Type="Int32" /> <asp:Parameter Name="dateExpires" DefaultValue='<%= DateTime.Now.ToString() %> 'Type="DateTime" /> </SelectParameters> </asp:SqlDataSource> ** NOTE the DateTime does not show up in blue - if that helps with a solution **