Click here to Skip to main content
15,868,340 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
Can anyone give me a example program code in asp.net using c# for insert data into sql server by using class,properties,Object.

"To use object in inline command"
Posted
Updated 6-Nov-14 4:13am
v3
Comments
Tomas Takac 6-Nov-14 8:40am    
Did you try google? There are tons of tutorials out there e.g. http://msdn.microsoft.com/en-us/library/aa581776.aspx
KaushalJB 6-Nov-14 8:42am    
Search in google and achieve it :-)
Make sure you read FAQs before posting questions.

check this SQL Server + C#: SELECT, INSERT, DELETE and UPDATE Queries and Stored Procedures[^]

and as Tomas indicated you should check on the Google. You need to put some efforts to get search the existing solution and if they dont work for you.

We are here to help you and get help.
 
Share this answer
 
Comments
Member 11166907 6-Nov-14 9:00am    
I want to create insert by creating object for that data with class and properties @ShwetaNMishra
I think You are Looking For this Format..


clsInsert.cs
C#
public class clsInsert
{
    public static int actInsert(sqlInsert obj)
    {
        int intRes = 0;
        try
        {
            //insert code here..
            if ("success")
            {
                intRes = 1;
            }
            else
            {
                intRes = 0;
            }
        }
        catch (Exception e1)
        {
            intRes = -1;
        }
        return intRes;
    }
}
public class sqlInsert
{
    public string UserName { get; set; }
    public string Password { get; set; }
}


Insert.aspx

C#
protected void btnInsert_Click(object sender, EventArgs e)
{
    sqlInsert clsObj = new sqlInsert();
    clsObj.UserName = txtUsername.Text;
    clsObj.Password = txtPassword.Text;
    int intres=clsInsert.actInsert(clsObj);
    if (intres == 1)
    {
        Response.Write("Success!");
    }
    else
    {
        Response.Write("Failed");
    }
}
 
Share this answer
 
go to this link
http://msdn.microsoft.com/en-us/library/aa581776.aspx[^]

you will get what you want

one suggestion
use forum like code project for those thing that really need help that will help you a in your development carear

As I paste here first link that I have got doing google
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900