घोषित करना चाहिए मैं सी # और एसक्यूएल में एक नौसिखिया हूं, मेरे पास यह SQL सम्मिलन कथन है जिसे मैं निष्पादित करना चाहता हूं। यह उन अन्य चरों के बीच तालिका नाम मांगता है जिन्हें मैं सम्मिलित करना चाहता हूं।तालिका परिवर्तनीय @table
तालिका चर @table
घोषित करना चाहिए इस कोड का एक हिस्सा है:
StreamReader my_reader = getFile(args);
string CS = formCS();
try
{
using (SqlConnection con = new SqlConnection(CS))
{
SqlCommand com = new SqlCommand("insert into @table (time, date, pin) values (@time, @date, @pin)", con);
con.Open();
Console.WriteLine("Enter table name:");
Console.Write(">> ");
string tblname = Console.ReadLine();
com.Parameters.AddWithValue("@table", tblname);
string line = "";
int count = 0;
while ((line = my_reader.ReadLine()) != null)
{
Dictionary<string, string> result = extractData(line);
com.Parameters.AddWithValue("@time", result["regTime"]);
com.Parameters.AddWithValue("@date", result["regDate"]);
com.Parameters.AddWithValue("@pin", result["regPin"]);
count += com.ExecuteNonQuery();
com.Parameters.Clear();
}
Console.WriteLine("Recoreds added : {0}", count.ToString());
Console.WriteLine("Press Enter to exit.");
}
Console.ReadLine();
}
catch (SqlException ex)
{
Console.WriteLine(ex.Message);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
किसी वैरिएबल के रूप में आपके सम्मिलित स्टेटमेट का टेबल नाम रखने की अनुमति नहीं है। अगर आपको कुछ चाहिए तो sp_exec में देखें उस। – rene