{"FROM 子句语法错误。"} mydataadapter.Fill(myds.me, "first1")这一句

DataAdapter Select Command - Sql Server
SqlDataAdapter
is a part of the ADO.NET Data Provider. SqlDataAdapter provides the communication between the Dataset and the Data Source with the help of
SqlConnection
Object .The SqlDataAdapter works with the DataSet to provide a disconnected data retrieval mechanism.
SelectCommand
property of the SqlDataAdapter is a Command object that retrieves data from the data source. The Fill method of the DataAdapter is used to populate a DataSet with the results of the SelectCommand . Fill method takes as its arguments a
to be populated, and a
DataTable object
, or the name of the DataTable to be filled with the rows returned from the SelectCommand. The following C# program shows the SqlDataAdapter using its SelectCommand property to retrieve the data from the Data Source.
using S
using System.D
using System.Data.SqlC
using System.Windows.F
namespace WindowsApplication1
{
public partial class Form1 : Form
public Form1()
InitializeComponent();
private void button1_Click(object sender, EventArgs e)
string connetionString =
SqlDataAdapter adapter = new SqlDataAdapter();
DataSet ds = new DataSet();
int i = 0;
connetionString = "Data Source=ServerNInitial Catalog=DatabaseNUser ID=UserNPassword=Password";
connection = new SqlConnection(connetionString);
connection.Open();
adapter.SelectCommand = new SqlCommand("Your SQL Statement Here", connection);
adapter.Fill(ds);
connection.Close();
for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
MessageBox.Show(ds.Tables[0].Rows[1].ItemArray[1].ToString());
catch (Exception ex)
MessageBox.Show(ex.ToString());
Mail to :&&&&&&
&& Founded by
All Rights Reserved. All other trademarks are property of their respective owners.c# Using Parameters.AddWithValue in SqlDataAdapter - Stack Overflow
to customize your list.
Announcing Stack Overflow Documentation
We started with Q&A. Technical documentation is next, and we need your help.
Whether you're a beginner or an experienced developer, you can contribute.
How can i use Parameters.Add.WithValue in 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:
da = new SqlDataAdapter("SELECT * FROM annotations WHERE annotation LIKE '%@search%'", _mssqlCon.connection);
da.SelectCommand.Parameters.AddWithValue("@search",txtSearch.Text);
var dt = new DataTable();
da.Fill(dt);
But failed. Could you help me where is my fault?
4,8242385144
The string used to initialize the SqlDataAdapter becomes the CommandText of the
property of the SqlDataAdapter.
You could add parameters to that command with this code
da = new SqlDataAdapter("SELECT * FROM annotations WHERE annotation LIKE @search",
_mssqlCon.connection);
da.SelectCommand.Parameters.AddWithValue("@search","%" + txtSearch.Text + "%");
First, remove the single quote around the parameter placeholder.
Second, add the wildcard character directly in the Value parameter of
AddWithValue
You have asked to use AddWithValue, but remember that, while it is a useful shortcut, there are also numerous drawbacks and all well documented.
author discuss how AddWithValue could give back wrong results in your
the author presents evidences of strong performance problems for
AddWithValue
So, the same code without AddWithValue and using the
syntax could be written as
da = new SqlDataAdapter("SELECT * FROM annotations WHERE annotation LIKE @search",
_mssqlCon.connection);
da.SelectCommand.Parameters.Add(new SqlParameter
ParameterName = "@search",
Value = "%" + txtSearch.Text + "%",
SqlDbType = SqlDbType.NVarChar,
Size = 2000
// Assuming a 2000 char size of the field annotation (-1 for MAX)
139k1382157
mySearchString = "Select * From test Where ([title] LIKE '%' + @title + '%')";
cmd.Parameters.Add("@title", SqlDbType.VarChar, 120);
cmd.Parameters("@title").Value = TextBox1.T
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you&#39;re looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enabledThis summer holiday,my parents allowed me to pay a visit to Puri,a very famous place in India.I have (1)h_________ about lots of sights at Puri from one of my classmates.I (2) w_________very impressed by the temples there.The first day of my holiday,I started off my journey to Puri.I (3) a_________ in Bhubaneswar first,and there I visited Lingaraj Temple.The next day,I took a bus to Puri.The (4) h_________ of summer here was strong in the daytime,so I had to spend the time on the beach in the evening.There I could (5) e_________ the cool summer nights.After two days’ stay,I went to Berhanpur.There I stayed at my friend’s house.I met many(6) l________ people when I climbed the hills with my friend.In the evening,we danced to music and sang songs on the beach.I had a (7) w________ time there.When I returned home,I had to pay (8) a __________ to my studies in order to make up for the lost time.As I spent the vacation (9) v_________ new places,I began my lessons with an excited heart.I felt that my journey to those places (10) i__________ my ability to work.
byVO25WE96
1.before2.HUB3.offer4car5.IDEA6.BUILT7.parking
为您推荐:
其他类似问题
扫描下载二维码}

我要回帖

更多关于 myds.synology.com 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信