InsertParameters Problem

Jan 25, 2008

Hi - any idea why I'm getting the following? I've got it to work on other pages with different data but I can't work it out.
 
thanks,
mander 
 
Object reference not set to an instance of an object.
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.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 32:     protected void Button1_Click(object sender, EventArgs e)
Line 33:     {
Line 34:         SqlDataSource1.InsertParameters["AdminNotes1"].DefaultValue = TextBox1.Text.ToString();
Line 35:         SqlDataSource1.Insert();
Line 36:     }
 

Source File: ..adminindex.aspx.cs    Line: 34

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
   Default2.Button1_Click(Object sender, EventArgs e) in c:Documents and Settings..adminindex.aspx.cs:34
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +75
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +97
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4886

View 6 Replies


ADVERTISEMENT

Insertparameters In Code-behind

Mar 1, 2007

Hi,How do I use insertparameters in code-behind? This is the code that I have  Dim insertSql As String
insertSql = "INSERT INTO [xyzTable] ([x], [y]) VALUES (@x, @y)"
SqlDataSource1.InsertCommand = insertSql
SqlDataSource1.InsertParameters.Add("@x", "124")
SqlDataSource1.InsertParameters.Add("@y", "456")
SqlDataSource1.Insert()  When I execute these line of code I get an error saying "Must declare the variable '@x'." Please help 

View 2 Replies View Related

InsertParameters For SqlDataSource

Nov 30, 2007

Hello, I have a SqlDataSource named "OrderHistoryDataSource" that I want to add a parameter to from the code behind file. THe reason I want to do this is todynamicly  add the UserID from a currently logged on user. What am I doing wrong? Is there a better way?My code below: --------------------------------------------------------------------Code behind file----------------------------------------------------------------------------using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class OrderHistory : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//If the user is not logged in this will redirect to Login.aspx
if (!Request.IsAuthenticated)
{
Response.Redirect("~/Login.aspx");
}

//test to display userID
MembershipUser myObject = Membership.GetUser();
string UserGUID = myObject.ProviderUserKey.ToString();

SqlDataSource DataSource = Page.FindControl("OrderHistoryDataSource");

DataSource.InsertParameters.Add("CurrentUserId", UserGUID.ToString());

DataSource.Select();
}
}
    --------------------------------------------------------------------Asp.net
file----------------------------------------------------------------------------<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="OrderHistory.aspx.cs" Inherits="OrderHistory" Title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="CONTENT" Runat="Server">
<table id="ContentTable">
<tr>
<td id="ContentTitleCell" colspan="3" style="width: 684px">
ORDER HISTORY</td>
</tr>
<tr>
<td colspan="3" rowspan="2" style="width: 684px">
<asp:GridView ID="OrderHistoryGrid" runat="server">
</asp:GridView>
 
<asp:SqlDataSource ID="OrderHistoryDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [UserOrders] WHERE ([UserID] = [CurrentUserID]) ORDER BY [OrderID]

VALUES (@UserId, @Address, @City, @State, @Zip)"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>">
<InsertParameters></InsertParameters>
</asp:SqlDataSource>
</td>
</tr>
<tr>
</tr>
</table>
</asp:Content>
   

View 3 Replies View Related

Correct InsertParameters Syntax

Jan 29, 2008

If someone can show me the correct syntax for the right side of the code below, I'd appreciate it.
srcMoreInfo.InsertParameters("Address").DefaultValue =       DirectCast(cuwMoreInfo.FindControl("txtAddress"), TextBox).Text 

View 11 Replies View Related

Passing ANY Value To The &<InsertParameters&> Section Of A SQLDataSource

Jun 6, 2007

Ok-I'm new at this, but just found out that to get data off a form and insert into SQL I can scrape it off the form and insert it in the <insertParameter> section by using  <asp:ControlParameter Name="text2" Type="String" ControlID="TextBox2" PropertyName="Text">  (Thanks CSharpSean) Now I ALSO need to set the user name in the same insert statement. I put in a UserName control that is populated when a signed in user shows up on the page. But in my code I've tried:                             <asp:ControlParameter Name="UserName" Type="String" ControlID="LoginName1"  DefaultValue="Daniel" PropertyName="Text"/> and I get teh errorDataBinding: 'System.Web.UI.WebControls.LoginName' does not contain a
property with the name 'Text'. So I take PropertyName="Text" out, and get the error:PropertyName must be set to a valid property name of the control named
'LoginName1' in ControlParameter 'UserName'. what is the proper property value?  SO.....BIG question...Is there a clean way to pass UserName to the insert parameters? Or ANY value for that matter? Id like to know how to write somehting likeString s_test = "test string";then in the updateparameter part of the sqldatasource pass  SOMEHITNG like (in bold)     <asp:Parameter Name="UserName" Type="String" Value=s_test /> Thanks in advance...again! Dan  

View 5 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved