Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
SqlConnection con = new SqlConnection("Data Source=ALIZEE_TROTT\\SQLEXPRESS;Initial Catalog=UrduStemmer;Persist Security Info=false; User ID=sa;Password=password");
SqlDataAdapter sda = new SqlDataAdapter("select * from stop_word_list where word_list='کو' ", con);
DataTable dt = new System.Data.DataTable();
sda.Fill(dt);
if (dt.Rows.Count == 1)
{
MessageBox.Show("Ok");
}
else
{
MessageBox.Show("not ok");
}
First make sure that your column for word_list is one of following type
nchar
nvarchar
ntext
You must precede all Unicode strings with a prefix N when you deal with Unicode string constants in SQL Server
SELECT * FROM stop_word_list WHERE word_list = N'کو'
Hope that helps.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I still new to C# and just have 3 months plus of learning process. I would like to seeking advice on how to extract data value from my DataTable I have create for validation checking.
private void checker
{
string sqlSelect2 = "SELECT a.AccNo, a.CompanyName , a.CreditLimit, FROM Debtor a JOIN";
}
which i have named TableCehecker, i do not need to put it to gridview, just for checking purposes.
In the private void process how can I extract dataTable TableCehecker and the value?
Thank you,
Brian
You need to follow the Docs from MSDN:
SqlConnection sqlConnection1 = new SqlConnection("Your Connection String");
SqlCommand cmd = new SqlCommand();
SqlDataReader reader;
cmd.CommandText = "SELECT * FROM Customers";
cmd.CommandType = CommandType.Text;
cmd.Connection = sqlConnection1;
sqlConnection1.Open();
reader = cmd.ExecuteReader();
// Data is accessible through the DataReader object here.
DataTable dt = new DataTable();
dt.Load(reader);
sqlConnection1.Close();
You can then check whatever you want of data inside the DataTable either by querying or by looping through the rows and checking the column values.
Based on your comments, to extract values from single row:
DataRow drow = dt.Rows[0];
string value = drow.Field<string>("CompanyName");
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I search on the net to execute oracle stored function and get the value of it
and I found something similar to this but i don't really understand it so i am not able to find out what's the error with it... please if someone can explan
whats happening after opening the connection with the database ?
public void Get_Office_Desc()
{
string oradb = "Data Source=mysource;User Id=emp;Password=00;";
var v_Office_code = Current_Office_code.Text;
string CommandStr = "F_Get_Office_Desc(:pOfficeCode)";
using (OracleConnection conn = new OracleConnection(oradb))
using (OracleCommand cmd = new OracleCommand(CommandStr, conn))
{
conn.Open();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new OracleParameter("pOfficeCode", v_Office_code));
cmd.Parameters.Add("pOfficeDesc", OracleType.Char, 128);
cmd.Parameters["pOfficeDesc"].Direction = ParameterDirection.ReturnValue;
cmd.ExecuteNonQuery();
var pOfficeDesc = Convert.ToString(cmd.Parameters["pOfficeDesc"].Value);
messagebox.show(pOfficeDesc);
}
}
You need to set CommandType to StoredProcedure - like that:
cmd.CommandType = CommandType.StoredProcedure;
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
MySQL database to combo box using mysqldatareader in c#.net
MySqlCommand cmd = new MySqlCommand("select * from product", connection);
MySqlDataReader dread = cmd.ExecuteReader();
while (dread.Read())
{
}
using mysqldatareader not a mysqldataadapter.
Wow...
Suppost your combox name is cbProducts, and you want fill it with the colum "description" of the query
MySQL database to combo box using mysqldatareader in c#.net
MySqlCommand cmd = new MySqlCommand("select * from product", connection);
MySqlDataReader dread = cmd.ExecuteReader();
while (dread.Read())
{
cbProducts.Items.Add(dread("description");
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
how to execute sql user defined function using c# same as that of executing stored procedure
You can use it like any other sql. Here's an example:
using (var con = new SqlConnection(Properties.Settings.Default.ConnectionString))
using (var cmd = new SqlCommand("SELECT dbo.IsInteger(#value);", con))
{
con.Open();
cmd.Parameters.Add("#value", SqlDbType.VarChar).Value = "10";
bool isInt = (bool)cmd.ExecuteScalar();
}
dbo.IsInteger is a scalar-valued function which returns a bit(true/false).
For the sake of completeness and even if it's not really related, here is it:
CREATE Function [dbo].[IsInteger](#Value VarChar(18))
Returns Bit
As
Begin
Return IsNull(
(Select Case When CharIndex('.', #Value) > 0
Then Case When Convert(int, ParseName(#Value, 1)) <> 0
Then 0
Else 1
End
Else 1
End
Where IsNumeric(#Value + 'e0') = 1), 0)
End
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am getting error while passing TVP to a stored procedure
My code is
SqlConnection con=new SqlConnection();
con.Open();
SqlCommand cmd=new SqlCommand("SPName",con);
DataTable dataTable = new DataTable("vpTableGuid");
dataTable.Columns.Add("id1", typeof(Guid));
dataTable.Columns.Add("rowNum", typeof(Int32));
dataTable.Rows.Add(Guid.NewGuid(),1);
dataTable.Rows.Add(Guid.NewGuid(),2);
dataTable.Rows.Add(Guid.NewGuid(),3);
SqlParameter param = new SqlParameter("#evaluatorList", dataTable);
param.SqlDbType = SqlDbType.Structured;
param.TypeName = "dbo.vpTableGuid";
command.Parameters.Add(param);
command.ExecuteNonQuery();
The above code throws an error:
INSERT into an identity column not allowed on table variables.
The data for table-valued parameter "#evaluatorList" doesn't conform to the table type of the parameter.
You cannot set the identity column manually in SQL.
Define your primary key column in SQL as such:
id1 UNIQUEIDENTIFIER DEFAULT NEWID() PRIMARY KEY
Remove this line of code:
dataTable.Columns.Add("id1", typeof(Guid));
And change your vpTableGuid definition to not include the id1 column.