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
|
 |
| 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
|
| 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
|
| 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
|
| 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
|
 |
| 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. |
|
|
 |
|