System.Data.SqlClient.SqlParameterCollection.GetParameter(String parameterName)

Posted by Atuldhiman under ASP.NET on 10/18/2012 | Points: 10 | Views : 1891 | Status : [Member] | Replies : 2
Hi ,
i am Atul . i write this code to record of list-box in table, but i am facing an error of sql.
In my table i have to columns id (int) which is primary and auto incremented and email(Varchar(50)).
Error i am facing is -
System.Data.SqlClient.SqlParameterCollection.GetParameter(String parameterName) at System.Data.SqlClient.SqlParameterCollection.get_Item(String parameterName) at contactsInvite.Save_E() in d:\Inetpub\wwwroot\PaypalCSharp\contactsInvite.aspx.cs:line 87
if any one help me with this.



public void Save_E()
{
SqlConnection connectionSql = new SqlConnection(Constr);
SqlCommand commandSql = new SqlCommand();
commandSql.Connection = connectionSql;
commandSql.CommandText = "INSERT INTO emailinvite (email) VALUES (@e)";
commandSql.Parameters.Add ("@e",SqlDbType.VarChar ) ;
try
{
connectionSql.Open();
for (int indexCounter = 0; indexCounter < lstContacts.Items.Count; indexCounter++)
{
commandSql.Parameters["email"].Value = lstContacts.Items[indexCounter].Text;
commandSql.ExecuteNonQuery();
}
connectionSql.Close();
}
catch (Exception exceptionMessage)
{
//show error message
Response.Write(" No Request send beacuse of" + exceptionMessage );
}
finally
{
commandSql.Dispose();
connectionSql.Close();
connectionSql.Dispose();
}
}


Regards,
Atul Dhiman
"Necessity is the mother of Invention"



Responses

Posted by: Atuldhiman on: 10/18/2012 [Member] Starter | Points: 25

Up
0
Down
Hi
Today i ask one question about the issue, i was facing some error of SQL to save ListBox control record in database.

I fix this issue. now all you can use it . It is error free and tested, i am using this for shopping cart..


 string Constr = @"Data Source..=\SQLEXPRESS;Initial Catalog..=;Integrated Security=True;Pooling=..";

public void Save_E()
{
SqlConnection connectionSql = new SqlConnection(Constr);
SqlCommand commandSql = new SqlCommand();
commandSql.Connection = connectionSql;
commandSql.CommandText = "INSERT INTO emailinvite (email) VALUES (@e)";
commandSql.Parameters.Add ("@e",SqlDbType.VarChar,50 ) ;
try
{
connectionSql.Open();
for (int indexCounter = 0; indexCounter < lstContacts.Items.Count; indexCounter++)
{
commandSql.Parameters["@e"].Value = lstContacts.Items[indexCounter].Text;
commandSql.ExecuteNonQuery();
}
connectionSql.Close();
}
catch (Exception exceptionMessage)
{
//show error message
Response.Write(" No Request send beacuse of" + exceptionMessage );
}
finally
{
commandSql.Dispose();
connectionSql.Close();
connectionSql.Dispose();
}
}


Regards,
Atul D

Regards,
Atul Dhiman
"Necessity is the mother of Invention"

Atuldhiman, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response