Related to data adapter
What things are mandatory in connection object
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Pravin MoreRank #1,419 · 1.2K reputationPosted Sep 21, 2011, 8:24 PM EDT
I think DataSource,UserID,Passward are mandatory....
but i think this may vary depend on type of connection and database....
Thanx,
Pravin.
Hemant KumarRank #1,202 · 1.5K reputationPosted Sep 21, 2011, 10:32 PM EDT
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;
}
}