Related to data adapter
What things are mandatory in connection object
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Hemant KumarPosted Sep 22, 2011, 2:32 AM
1. ConnectionString
2. Connection Object
3. DataAdapter
4. To Store Data we need DataSet
e.t.c
Please see this example like this you need to write
public string SaveData(string firstName, string lastName)
{
try
{
String connectionString = ConfigurationManager.ConnectionStrings["TESTDB"].ConnectionString;
string result = Boolean.FalseString;
using (SqlConnection connection = new SqlConnection(connectionString))
{
SqlCommand cmd = new SqlCommand();
cmd.Connection = connection;
cmd.CommandText = String.Format("insert into Hemanth_DB.dbo.PersonName(FirstName,LastName) values ('{0}','{1}')", firstName, lastName);
//cmd.CommandText = "insert into Hemanth_DB.dbo.PersonName(FirstName,LastName) values (@FirstName,@LastName)";
//cmd.Parameters.Add(new SqlParameter("@FirstName", firstName));
//cmd.Parameters.Add(new SqlParameter("@LastName", lastName));
cmd.CommandType = CommandType.Text;
connection.Open();
int count = cmd.ExecuteNonQuery();
if (count > 0)
{
result = Boolean.TrueString;
}
else
{
result = Boolean.FalseString;
}
}
return result;
}
catch (Exception exp)
{
return exp.Message;
}
}
Pravin MorePosted Sep 22, 2011, 12:24 AM
I think DataSource,UserID,Passward are mandatory....
but i think this may vary depend on type of connection and database....
Thanx,
Pravin.