C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




in an upload control


Posted Date: 28 Aug 2008      Total Responses: 3

Posted By: sana       Member Level: Silver     Points: 1


hii everyone
can u tell me how can i get correct execution of this program

am getting error at the ent that is this statement
int numRowsAffected = command.ExecuteNonQuery();

can u tell me the recovery please
SqlCommand command = new SqlCommand("INSERT INTO Image (img_name,img_data,img_contenttype) VALUES ( @img_name, @img_data,@img_contenttype )", connection);

SqlParameter param0 = new SqlParameter("@img_name", SqlDbType.VarChar, 50);
param0.Value = imgName;
command.Parameters.Add(param0);

SqlParameter param1 = new SqlParameter("@img_data", SqlDbType.Image);
param1.Value = imgbin;
command.Parameters.Add(param1);

SqlParameter param2 = new SqlParameter("@img_contenttype", SqlDbType.VarChar, 50);
param2.Value = imgcontenttype;
command.Parameters.Add(param2);

connection.Open();
int numRowsAffected = command.ExecuteNonQuery();
connection.Close();




Responses

Author: ANIL PANDEY    28 Aug 2008Member Level: DiamondRating:     Points: 2
Hello,


U can refer this Code for Inserting the values in the data base..

protected void btnApplay_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(strConStr);
SqlCommand cmd = new SqlCommand();
DateTime dtFrom = Convert.ToDateTime(txtFromDate.Text.ToString() );
DateTime dtTo = Convert.ToDateTime(txtTodate.Text.ToString());
TimeSpan ts;
UID = Convert.ToInt32( Session["UID"].ToString());
string strQuery = string.Empty;
string strStatus = "Pending";
double ldblDays;
int lintResult;

ts = Convert.ToDateTime(dtTo).Subtract(dtFrom);
ldblDays = ts.Days + 1;

//Checking for the hal/Full Day
if( (ddlHF.SelectedItem.Text == "Half") && (ldblDays > 1))
{
lblMsg.ForeColor = System.Drawing.Color.Red;
lblMsg.Text = "You can not select more than one day as Half day.";
ddlHF.Focus();
}
else
{
if ((ddlHF.SelectedItem.Text == "Half") && (ldblDays == 1))
{
ldblDays = 0.5;
}

if (CheckApplication(ldblDays))
{
con.Open();
strQuery = "insert into tbLeaveDetails values(" + UID + ",'" + txtFromDate.Text.Trim() + "','" + txtTodate.Text.Trim() + "'," + ldblDays + ",'" + ddlType.SelectedItem.Text + "','" + strStatus + "')";
cmd.Connection = con;
cmd.CommandType = CommandType.Text;
cmd.CommandText = strQuery;
lintResult = cmd.ExecuteNonQuery();

if (lintResult > 0)
{
lblMsg.ForeColor = System.Drawing.Color.Green;
lblMsg.Text = "Leave sent for approval.";
txtFromDate.Text = "";
txtTodate.Text = "";
ddlHF.SelectedIndex = 0;
ddlType.SelectedIndex = 0;
fillGrid();
}
else
{
lblMsg.ForeColor = System.Drawing.Color.Red;
lblMsg.Text = "Error while sending leave request.";
}
}
// Closing the Connection
con.Close();
cmd.Dispose();
con.Dispose();
}

}


Thanks
Anil


Author: Sakthi    28 Aug 2008Member Level: BronzeRating:     Points: 2
Try in this way, I hope u wouldnt get any error.
int numRowsAffected = (int) command.ExecuteNonQuery();

All the best.


Author: Raju.M    28 Aug 2008Member Level: GoldRating:     Points: 4
i think u want id from database when u insert to DB

then u change ur code like this
string command="INSERT INTO database(X,Y,Z)VALUES (@0,@1,@2);SELECT CAST(scope_identity() AS numeric);";
//
int numRowsAffected =COnvert.toInr32(command.ExecuteNonQuery());



Post Reply
You must Sign In to post a response.
Next : check a checkbox in datagridview
Previous : treeview control
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design

web conferencing services

Contact Us    Privacy Policy    Terms Of Use