sqldataadapter

With ADO, using SqlDataAdapter.FillSchema clears @ReturnValues and other stored procedure parameters marked for output

你。 提交于 2021-02-19 06:15:53
问题 [Edit - an explanation of the answer is at the foot of the question because the subtlety is not totally obvious from the accepted answer.] Original question: I am looking for a quick 'yes this approach should be possible' answer before I commit further effort. Scenario: I have a simple SQL Server stored procedure that runs a query. I also want to (1) return a varchar(100) parameter declared as OUTPUT , and (2) use the @ReturnValue to return a further (integer) value. I call this procedure

Use SqlDataAdapter and DataTable to get and update on SQL server with PowerShell

最后都变了- 提交于 2020-06-12 10:04:27
问题 I am trying to use PowerShell to get a System.Data.DataTable from an SQL server, edit the data, and update it back to the SQL server but I cannot get it to work. The below code runs/executes but the data is not changed. $sqlConnection = new-object System.Data.SqlClient.SqlConnection("Server=server,1234; Database=dingo; Trusted_Connection=True;") $sqlConnection.open() $sqlCommand = $sqlConnection.CreateCommand() $sqlCommand.CommandText = "SELECT * FROM dbo.test" $dt = new-object System.Data

Use SqlDataAdapter and DataTable to get and update on SQL server with PowerShell

倾然丶 夕夏残阳落幕 提交于 2020-06-12 10:04:09
问题 I am trying to use PowerShell to get a System.Data.DataTable from an SQL server, edit the data, and update it back to the SQL server but I cannot get it to work. The below code runs/executes but the data is not changed. $sqlConnection = new-object System.Data.SqlClient.SqlConnection("Server=server,1234; Database=dingo; Trusted_Connection=True;") $sqlConnection.open() $sqlCommand = $sqlConnection.CreateCommand() $sqlCommand.CommandText = "SELECT * FROM dbo.test" $dt = new-object System.Data

SqlDataAdapter Get Identity after insert

别说谁变了你拦得住时间么 提交于 2020-01-24 22:21:08
问题 I create a SqlDataAdapter after a fill it to Dataset . My question is that after insert I want to get the IDENTITY value for primary column. For example a give buttonedit1 editvalue is Id (this is my primary column) after insert I want to get Identity value in ButtonEdit1 text. Can I make this unless use SQL command like Select @IDentity thanks. public void Form1_Load(object sender,EventArgs e) { try { SqlConnection con = new SqlConnection(@"ConString"); con.Open(); adap = new SqlDataAdapter(

C# SqlDataAdapter.Update()

让人想犯罪 __ 提交于 2020-01-17 07:33:06
问题 Im going crazy with this. I did the ff: Create a datatable. Fill it from a SQL db thru SqlDataAdapter. Edit the datatable thru datagridview. Call the sqldataadapter.update but the changes are not persisted to the db. A closer look at the datatable after editing, the row states were not updated even if i actually edited the datatable thru the datagridview but the edited DataRow(s) have changes in the item array. Really confusing.. Any ideas? Thanks. 回答1: You need several things to make this

SqlDataAdapter.Fill takes time more than CommandTimeout

别等时光非礼了梦想. 提交于 2019-12-24 09:26:34
问题 When I execute this query, though I set the ConnectionTimeOut to 1 second, SqlDataAdapter.Fill takes more time than 65 second. and timeout not work. var cmd = new SqlCommand(); cmd.CommandType = CommandType.Text; cmd.CommandText = "select * FROM [tblLargeData]"; con.Open(); cmd.Connection = con; var ds = new DataSet(); var da = new SqlDataAdapter(cmd); da.SelectCommand.CommandTimeout = 1; da.Fill(ds); tblLargeData is a table that contains large data in SQL server database. But when I change

Selecting different connection strings for data gridview

岁酱吖の 提交于 2019-12-24 07:29:26
问题 Why is this not straight-forward? I have two databases that contain a log-table each. I have a stored procedure that extracts the data from the table. I have a datagridview on a windows form, and a drop-down box to select the connection string for the respective databases. On selection of the conn string, I want to change the datagridview to contain the log messages in the selected database. My code: Select Case cboConnection.Text Case "CP DEV" LogConnectionString = "Data Source=SAMBAR.gofast

Trying to pass SqlCommand in SqlDataAdapter as parameters

会有一股神秘感。 提交于 2019-12-24 02:27:07
问题 I've successfully built up my method to execute a select command. It is working fine. Then I change my code for SqlDataAdapter DA = new SqlDataAdapter(); I tried to pass SqlCommand as CommandType.Text in the parameters but I can not do it successfully. I get error. Is there any way if I can pass it as parameters. Please see my code. Running code (aspx page code) if ((!string.IsNullOrEmpty(user_login.Value)) && (!string.IsNullOrEmpty(user_pass.Value))) { // username & password logic DataTable

How to retrieve column values separately through sql data adapter class?

大兔子大兔子 提交于 2019-12-23 05:26:58
问题 I am trying to learn how to use sql data adapter ... I have coded the following to check how it works ... the problem is i want to retrieve values of 3 columns(DeptNo,DeptId,DeptName) of my database table "Sana" separately and display them in three separate text boxes ... Through the code mentioned below I am able to retrieve the value of entire tuple of data base table together what should I do to reach above mentioned result??? protected void Button1_Click(object sender, EventArgs e) {

c# Using Parameters.AddWithValue in SqlDataAdapter

不羁的心 提交于 2019-12-17 05:05:18
问题 How can I use Parameters.AddWithValue with an SqlDataAdapter. Below searching codes. var da = new SqlDataAdapter("SELECT * FROM annotations WHERE annotation LIKE '%"+txtSearch.Text+"%'", _mssqlCon.connection); var dt = new DataTable(); da.Fill(dt); I rewrote the code like this: SqlDataAdapter da; da = new SqlDataAdapter("SELECT * FROM annotations WHERE annotation LIKE '%@search%'", _mssqlCon.connection); da.SelectCommand.Parameters.AddWithValue("@search",txtSearch.Text); var dt = new