hi frnds,
i want to know, can we pass sqlcommand object to sql dataadapter.
please let me know,
Thanks,
aamir
Loading
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 30, 2011, 4:39 AM EDT
do it like this..........
SqlConnection con1 = new SqlConnection("Data Source=xxxx;Initial Catalog=xxxx;Persist Security Info=True;User ID=xxxxx;Password=*****");
SqlCommand cmd1 = new SqlCommand("Select * from TableName", con1);
SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
DataSet ds1 = new DataSet();
da1.Fill(ds1);
Thanx,Hope this solve your problem.
Pravin.
Satyapriya NayakRank #47 · 31.5K reputationPosted Sep 30, 2011, 5:59 AM EDT
using System.Data;
using System.Data.SqlClient;
SqlConnection con=new SqlConnection("server=localhost;uid=sa;pwd=;database=std");
SqlCommand com;
SqlDataAdapter sqlda;
DataSet ds;
private void btnload_Click(object sender, System.EventArgs e)
{
con.Open();
str="select * from student";
com=new SqlCommand(str,con);
sqlda=new SqlDataAdapter(com);
ds=new DataSet();
sqlda.Fill(ds,"student");
dataGrid1.DataSource=ds;
dataGrid1.DataMember=("student");
con.Close();
}
Thanks
sujit bista3 reputationPosted Jan 7, 2013, 8:34 PM EST
Public Class Form1
'Dim sq As SqlCommandBuilder
Dim adp As SqlDataAdapter
Function RetDataTable() As DataTable
Dim dt As New DataTable
Dim _Connection As New SqlConnection("Server=mac-dols;UID=sa;PWD=macdols12;Database=db1")
Dim com As New SqlCommand()
com.CommandType = CommandType.StoredProcedure
com.CommandText = "procname"
com.Connection = _Connection
com.Parameters.AddWithValue("@count", "2")
adp = New SqlDataAdapter(com)
' sq = New SqlCommandBuilder(adp)
adp.Fill(dt)
Return dt
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DataGridView1.DataSource = RetDataTable()
End Sub
End Class