Showing posts with label store. Show all posts
Showing posts with label store. Show all posts

Friday, March 9, 2012

problem when iserting in table

I'm building a form that collects some info from the user (user name, password and type ) and I need to store this info into a table called USER that I created.

I'm using 3 text boxes and a button, when the user clicks the button I need to collect this info and store it into my table

when i click the button i get an error msg in this line (comm.ExecuteNonQuery(); )

what do i need to do?

here is the code

protectedvoid Button1_Click(object sender,EventArgs e)

{

string str ="data source=(local);initial catalog=NH_Project1;integrated security=true;";

SqlConnection conn =newSqlConnection(str);

int rows;

SqlCommand comm =newSqlCommand("INSERT INTO [USER](UserId, UserName, UserPassword, Type)VALUES" +

"@.UsrName,@.UsrPass,@.UsrType", conn);

comm.CommandType =CommandType.Text;

comm.Parameters.AddWithValue("@.UsrName",TextBox1.Text);

comm.Parameters.AddWithValue("@.UsrPass",TextBox2.Text);

comm.Parameters.AddWithValue("@.UsrType", TextBox3.Text);

conn.Open();

rows= comm.ExecuteNonQuery();

conn.Close();

louayazar:

comm.Parameters.AddWithValue("@.UsrName",TextBox1.Text);comm.Parameters.AddWithValue("@.UsrPass",TextBox2.Text);

comm.Parameters.AddWithValue("@.UsrType", TextBox3.Text);

Remove the "@." symbol from your AddWithValue calls. Also, I'd recommend enclosing your ExecuteNonQuery call within a Try/Catch block so you can capture any errors in the future.

|||

Hii

I tried to remove the "@." like what you said but that doesn't work, I still have the same error MSG when clicking the button.

|||

Then make sure to put your ExecuteNonQuery call into a Try/Catch block and see what exception you get. This should help you find out what's going on.

|||

that was helpful, thanks a bunch

Saturday, February 25, 2012

problem using ntext

Hi, I'm using a column(ntext) to store some long strings. An example of the string that I need to store is the following:

436;Implementing A Gang - Awareness Program/And A Middle SchoolGang Prevention Curriculum. Doctoral Th;Samuels;Donald J;MiamiIV;Administrators; At Risk; Child And Youth Studies; Community;Community Members; Drop Out Prevention; Educational Leadership;Law/Criminal Justice; Peer Counseling; Principals; Secondary Education

I wrote a store procedure that does it, but it seems that the columnspace is not enough for the above string. The string in fact, istruncated and only the following portion is stored in my table:

436;Implementing A Gang - Awareness Program/And A Middle School Gang Prevention Curriculum. Doctoral Th;Samuels;Donald J;MiamiIV;Administrators; At Risk; Child And Youth Studies; Community;Community Members; Drop Out Prevention; Educational Leadership

What can I do?

ChristianIf you are not storing more than 4000 characters you can use NVarChar 4000 is the limit. The reason there are issues with NText and limitations. Hope this helps.|||I have just changed the column type from text to varchar(4000).
But I still have the same problem.

Christian|||

Try the link below for working code sample. Hope this helps.

http://msdn2.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.insertcommand.aspx

|||

christianmala:

I wrote a store procedure that does it, but it seems that the columnspace is not enough for the above string. The string in fact, istruncated and only the following portion is stored in my table:


How are you checking what is stsored in your table? I highly suspect you are using Query Analyzer, which by default will only display the first 256 characters in a column. To change this value in QA, Tools - Options - Results - Maximum characters per column. Change 256 to something larger.|||Oh God,
you are so right!!!!!

Thanks,

Christian