insert data in datasource C# Friends
http://www.csharpfriends.com
World's Greatest C# Community    
Home Articles C# Forums Books C# Syntax C# Spec C# Jobs free Source Code Advertise About
 

Control Panel

[ Sign In / register ]
Points   
Notes 
My Forums
My Tutorials
My Profile

Resources

Learn
 Articles
 QuickStarts
 C# Spec
 Whitepapers
 Tools
 Class Browser
 C# Code Generator
 Links
 Misc Rss Feeds
 Code Highlight
 411 Directory
 FREE magazines
 freevb.net

Reviews
  ASP.NET Hosting

Source Code
 Get Version 1.0



C# Consulting
AspDotNetStoreFront

C# Forums Home   Search   Login   Register   Member List  
CSharpFriends  > CSharpAspNetAnyQuestionIsOk  > insert data in datasource  
 
Previous Thread :: Next Thread 
 Author Thread: insert data in datasource
Spartukus is not online. Last active: 11/28/2009 9:14:25 AM Spartukus
Joined: 13 Oct 2009
Total Posts: 11
 
insert data in datasource
Posted: 13 Nov 2009 07:50 AM
hey guys on my button click for my asp.net web form I get a problem

SqlDataSource1.Parameters.Add("@Something", TextBox25.Text);

the rest of the code is fine but I get a missing directive or assembly error error for Paramaters its not been defined :S Dont know where to go from here?


vulpes is not online. Last active: 11/13/2009 3:05:34 PM vulpes
Top 25 Poster
Joined: 30 Apr 2007
Total Posts: 6800
 
Re: insert data in datasource
Posted: 13 Nov 2009 08:08 AM
I think the name of the property should be SelectParameters not just Parameters.
Spartukus is not online. Last active: 11/28/2009 9:14:25 AM Spartukus
Joined: 13 Oct 2009
Total Posts: 11
 
Re: insert data in datasource
Posted: 13 Nov 2009 08:15 AM
hey thanks vulpes you wer correct but for all the time I waisted on that it didnt work, man inserting to a database is hard. Back to the drawing board!
Spartukus is not online. Last active: 11/28/2009 9:14:25 AM Spartukus
Joined: 13 Oct 2009
Total Posts: 11
 
Re: insert data in datasource
Posted: 13 Nov 2009 10:48 AM
protected void Button3_Click(object sender, EventArgs e)
{
SqlDataSource SqlDataSource1 = new SqlDataSource();
SqlDataSource1.ConnectionString = ConfigurationManager.ConnectionStrings["CustomersConnectionString"].ConnectionString;

SqlDataSource1.InsertCommandType = SqlDataSourceCommandType.Text;
SqlDataSource1.InsertCommand = "INSERT INTO CustomerTable(FirstName, SecondName, AddressLine1, PostCode, TelephoneNumber) VALUES (@FirstName, @SecondName, @AddressLine1, @PostCode, @TelephoneNumber)";

SqlDataSource1.InsertParameters.Add("@FirstName", TextBox1.Text);
SqlDataSource1.InsertParameters.Add("@SecondName", TextBox2.Text);
SqlDataSource1.InsertParameters.Add("@Address", TextBox3.Text);
SqlDataSource1.InsertParameters.Add("@PostCode", TextBox4.Text);
SqlDataSource1.InsertParameters.Add("@TelephoneNumber", TextBox5.Text);


// why wont this work? :(
int rowsAffected = 0;

try
{
rowsAffected = SqlDataSource1.Insert();
}
catch
{
Server.Transfer("Default.aspx");
}

finally
{
SqlDataSource1 = null;
}
if (rowsAffected != 0)
{
Server.Transfer("Failed.aspx");
}
else
{
Server.Transfer("Default.aspx");
}

}


keep getting an error Object reference not set to an instance of an object. check to determine the object is null before calling the method?

Any one able to help?
Spartukus is not online. Last active: 11/28/2009 9:14:25 AM Spartukus
Joined: 13 Oct 2009
Total Posts: 11
 
Re: insert data in datasource
Posted: 13 Nov 2009 10:48 AM
thats for this line

SqlDataSource1.ConnectionString = ConfigurationManager.ConnectionStrings["CustomersConnectionString"].ConnectionString;
vulpes is not online. Last active: 11/13/2009 3:05:34 PM vulpes
Top 25 Poster
Joined: 30 Apr 2007
Total Posts: 6800
 
Re: insert data in datasource
Posted: 13 Nov 2009 01:31 PM
I'd try hard-coding the connection string rather than getting it from the configuration file.

This will tell you whether the database code is working properly or not. If it is working, then the problem must lie with the configuration file.
Previous Thread :: Next Thread 
Page 1 of 1
 
CSharpFriends  > CSharpFriends  > CSharpAspNetAnyQuestionIsOk  > insert data in datasource  



Today's Top Movers

Yesterday Top Movers


Monthly Leaders

Top Members

Great Offers
.net hosting
Go To My Pc
Remote Pc Control
C#
ad server
snadtech GoToMyPc

Top of Page

Advertise | SiteMap | About | Link To Us | Privacy Notice Copyright © 2003 - 2005 CSharpFriends.com  All Rights Reserved  Visual C# Developer Center